MIDTERM TUTORIALS Flashcards

(32 cards)

1
Q

Define software in detail !

A

Software is an intangible product that is built by software professionals for a particular market or general market and consists of instructions, data structures, and documentation.

  • Instructions (computer programs) that, when executed provide desire features, functions, and performance
  • Data structures that enable the programs to adequately store and manipulate information
    -Documentation that describes the operation and use of the programs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe the differences between Software Engineering and Software Engineer.

A

Software Engineering: This is an engineering discipline concerned with all aspects of software production. It involves the establishment and use of sound engineering principles to economically obtain software that is reliable and works efficiently on real machines. It covers the entire lifecycle, from initial system specification through to maintaining the system after it has gone into use. It’s not just about the technical process of development but also includes project management, and the development of tools and methods to support software production.

Software Engineer: A software engineer is an individual who applies the principles and practices of software engineering to the design, development, testing, and maintenance of software systems. They are the practitioners who develop solutions for application-specific problems for clients, using computers, programming languages, tools, techniques, and methods. They work in multiple application domains and are responsible for creating the software products.

In essence, Software Engineering is the discipline and process, while a Software Engineer is the professional who practices that discipline.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Dr. Koh asked SmartDeveloper to develop a medical system for his clinic, but he does not want to spend much. SmartDeveloper advised him to purchase an existing medical management system at a lower cost and utilize all the features provided to minimize expenses.

A

Based on the situation, the type of software product SmartDeveloper advised Dr. Koh to purchase is a Generic Product.

Here’s why, along with two features:

Type of Software Product: Generic Product. These are stand-alone systems that are developed for a general market and sold to any customer who wishes to buy them. An “existing medical management system” fits this description as it’s likely designed to cater to the common needs of many clinics, rather than being custom-built for Dr. Koh’s specific, unique requirements.

Two Features of Generic Products relevant to the scenario:

Lower Initial Cost: As SmartDeveloper advised, purchasing an existing system is at a “lower cost.” This is a key characteristic of generic products because the development costs are spread across many customers, making the individual purchase price more affordable compared to developing a custom solution from scratch.

Readily Available Features: SmartDeveloper advised Dr. Koh to “utilize all the features provided.” Generic products come with a pre-defined set of functionalities designed to cover common needs within their target market (in this case, medical clinics). While not every feature might be used, the system is ready to use “off-the-shelf” with a broad range of capabilities.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain FIVE activities of a generic process framework.

A
  • Communications : communicate with customers to understand objectives and requirements
  • Planning creates a “map” to define the work by describing the tasks, risks, and resources, work products, and work schedule.
  • Modeling creates a “sketch”, what it looks like architecturally and how the constituent parts fit together and other characteristics.
  • Construction: code generation and the testing
  • Deployment : delivered to the customer who evaluates the product and provides feedback based on the evaluation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Give TWO reasons why SDLC is important for Software Development.

A

1, It provides a standardized framework that defines activities and deliverables.
This ensures a structured approach to development.

  1. It aids in project planning, estimating, and scheduling, allowing for better resource management and timeline control.
  2. It makes project tracking and control easier
  3. It increases the speed of development
  4. It improves client relations
  5. It decreases project risks
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Assuming you plan to develop a “Calorie Intake Application”. Identify TWO problem statements and explain the objectives of the Planning and Analysis stages.

A

Problem Statements for a “Calorie Intake Application”:

Problem Statement 1: Users struggle to accurately track their daily calorie consumption, leading to difficulties in managing their dietary goals.

Objectives of the Planning and Analysis Stages for this Application:

Planning Stage Objectives:
- Gather business requirements from potential users (e.g., individuals trying to lose weight, maintain health, or gain muscle) and stakeholders (e.g., nutritionists, fitness trainers).

  • Determine who will use the system (e.g., general public, specific demographic), how they will use it (e.g., daily logging, recipe analysis), what data should be input (e.g., food items, portion sizes, user activity levels), and what data should be output (e.g., total daily calories, macronutrient breakdown, progress reports). This would involve inputs from users, market surveys on health and fitness apps, and perhaps domain experts like dietitians.

Analysis Stage Objectives:

  • Outline the scope of the “Calorie Intake Application” and identify potential solutions or features to address the problem statements.
  • Analyze the gathered requirements, converting the information from the planning phase into clear, detailed requirements for the development team. For instance, specifying how the app will calculate calories for various foods, or how it will store user data.
  • Create a Software Requirement Specification (SRS) document that will serve as a guideline for the design and development of the application. This SRS will list all product requirements, such as features for logging meals, searching a food database, tracking exercise, and displaying nutritional information.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Final approval before start development.
Produce software design document and using flowchart represent system flow.
In most cases, the design phase will include the development of prototype model.

a) What stage in the SDLC describes the above statements?
b) What is the role of the prototype? Is it compulsory

A

(a) The stage described is the Design phase
(b) The role of a prototype is to create a pre-production version of the product, which allows the team to:

  • Visualize what the product will look like.
  • Give the team an opportunity to make changes without the hassle of rewriting extensive code.

It is not strictly compulsory in all cases, but “in most cases, the design phase will include the development of prototype model”, suggesting it’s a highly recommended and common practice.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Explain “Actual problems come up during the maintenance phase”.

A

The statement “Actual problems come up during the maintenance phase” means that once customers start using the developed system in their real-world environment, issues that were not identified during development or testing can emerge. These can be defects (bugs), areas where the system doesn’t behave as expected under certain conditions, or new requirements that arise as users interact with the software over time. This phase involves taking care of the developed product by addressing these reported issues. In some instances, defects found can be significant enough to necessitate going back to earlier stages of the SDLC, even the first step.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain how Agile Testing can deliver a product faster.

A
  • It is an iterative development methodology. Instead of waiting for the entire development to complete, testing is carried out continually alongside development.
  • This continuous testing provides continuous feedback to the development phase from the very start.
  • By integrating testing throughout the development sprints (design, build, test, review cycles), issues are identified and fixed earlier in the process. This prevents the accumulation of defects that would require significant time to resolve at the end, thus speeding up the delivery of a functional product increment by increment.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Describe the purpose of testing and the relation between testing and integration in SDLC.

A
  • Purpose of Testing: The purpose of testing is to ensure that the developed software product is actually solving the needs that were identified and gathered during the requirements phase. It involves checking the code against these requirements and performing various types of functional and non-functional tests (like performance, security, usability, etc.) to identify bugs or defects. The goal is to ensure the product reaches the quality standards defined in the Software Requirement Specification (SRS).
  • Relation between Testing and Integration: Testing and Integration are closely related in the SDLC. After the code is developed and individual modules or units are tested, Integration involves combining these different parts of the software. Testing is then performed on these integrated components to ensure they work together correctly. After successful testing confirms the product meets quality standards, it is delivered or deployed to the customer, which is part of the integration process. Testers report bugs found during this phase, which are then fixed and retested until the product is stable for delivery.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Identify four management methods and techniques and explain each of them with an example.

A
  1. Project Planning: This involves defining the project scope, objectives, tasks, timelines, resources, and budget.

Example: For the “Calorie Intake Application,” project planning would involve outlining all features to be developed, estimating the time required for each (e.g., 2 weeks for user registration, 4 weeks for food database integration), assigning developers to tasks, and setting a budget for tools or licenses. This would also include scheduling activities as seen in the SDLC phases.

  1. Project Tracking & Oversight: This is the process of monitoring project progress against the plan, identifying deviations, and taking corrective actions to keep the project on track.

Example: If the development of the food logging feature for the “Calorie Intake Application” is taking longer than scheduled (as identified through tracking), the project manager would oversee the situation, perhaps by allocating more resources or adjusting the scope, to ensure the project milestones are met. This makes project tracking and control easier.

  1. Quality Assurance (QA): This involves implementing processes and standards throughout the SDLC to ensure the final product meets the desired quality levels and customer expectations.

Example: For the “Calorie Intake Application,” QA would involve conducting regular code reviews, ensuring all features described in the SRS are implemented correctly, and performing comprehensive testing (unit, integration, system, usability testing ) to catch bugs before release. The goal is to produce superior software that meets and exceeds customer expectations.

  1. Configuration Management: This technique involves managing and controlling changes to the software’s artifacts, including code, design documents, and requirements, throughout the development lifecycle.

Example: If a new requirement arises for the “Calorie Intake Application,” such as adding a feature to scan barcodes for nutritional information, configuration management ensures that this change is properly documented, reviewed, approved, and implemented, and that all related documents (like the SRS and SDD ) are updated accordingly. This helps in tracking different versions of the software and its components.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Identify TWO SDLC models that are suitable for small projects and discuss
3 advantages and 3 disadvantages of the proposed models.

A
  1. Waterfall Model 💧

Suitability for Small Projects: Works well for smaller projects where requirements are very well understood.

Advantages:

Simple and easy to understand and use.
Easy to manage due to the rigidity of the model; each phase has specific deliverables and a review process.
Phases are processed and completed one at a time.
Disadvantages:

No working software is produced until late in the life cycle.
High amounts of risk and uncertainty.
Cannot accommodate changing requirements.

  1. Big Bang Model 💥

Suitability for Small Projects: This model is usually used for small projects. It is also considered suitable for small, experimental, or academic projects with undefined requirements and flexible timelines.

Advantages:

This is a very simple model.
Little or no planning required.
Easy to manage.
Disadvantages:

Very High risk and uncertainty.
Not a good model for complex and object-oriented projects.
It can turn out to be very expensive if requirements are misunderstood.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Identify TWO SDLC models that are suitable for big projects and describe 3 advantages and 3 disadvantages of the proposed model.

A
  1. Spiral Model 🌀

Suitability for Big Projects: Useful for large and mission-critical projects. It’s also indicated for large to medium, high-budget projects with critical risk evaluation and undefined requirements.

Advantages:

High amount of risk analysis.
Changing requirements can be accommodated.
Allows extensive use of prototypes.
Disadvantages:

Can be a costly model to use.
Risk analysis requires highly specific expertise.
Management is more complex.
2. Iterative Model 🔄

Suitability for Big Projects: While one disadvantage notes it’s “not suitable for smaller projects”, implying its utility for larger ones, the table on page 29 suggests it’s for projects that “allow incremental delivery an require ongoing refinement”, which often aligns with the complexity of big projects. The document primarily details its iterative nature which can be beneficial for managing large scopes in portions.

Advantages:

Testing and debugging during smaller iteration is easy.
A Parallel development can be planned.
Risks are identified and resolved during iteration.
Disadvantages:

It is not suitable for smaller projects.
More Resources may be required.
Project completion date not confirmed because of changing requirements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the difference between Verification and Validation in the V model?

A

In the V-Model:

Verification: It involves a static analysis method (review) done without executing code. It is the process of evaluating the product development process to find whether specified requirements are met. In the V-Model diagram, verification phases include activities like reviewing business requirement specifications, system requirement specifications, high-level design, and low-level design.

Validation: It involves a dynamic analysis method (functional, non-functional), and testing is done by executing code. Validation is the process to classify the software after the completion of the development process to determine whether the software meets the customer’s expectations and requirements. In the V-Model diagram, validation phases include acceptance testing, system integration testing, component testing, and unit testing, which correspond to the verification phases.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Identify and explain the FIVE stages included in the RAD model.

A
  1. Business Modelling:

The business model for the product is designed in terms of the flow of information and its distribution between various business channels.
A complete business analysis is performed to find vital information for the business and how it can be obtained.

2.Data Modelling:

The attributes of all data sets are identified and defined.
The relation between these data objects is established and defined in detail in relevance to the business model.

  1. Process Modelling:
    Data object sets from the Data Modelling phase are converted to establish the business information flow needed to achieve specific business objectives per the business model.
    Process descriptions for adding, deleting, retrieving, or modifying a data object are given.
  2. Application Generation:

The actual system is built, and coding is done by using automation tools to convert process and data models into actual prototypes.

5.Testing and Turnover:

The overall testing time is reduced in the RAD model as the prototypes are independently tested during every iteration. This phase focuses on delivering the tested application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

(a) In your opinion, what is the purpose of a prototype in system development?

A

It allows for a “working” model of the system to be built before actual development, even if it’s a toy implementation or a simplified/minimal version.
It helps users get a better understanding of the system being developed because a working model is displayed.
It aids in reducing time and cost as defects can be detected much earlier.
It facilitates quicker user feedback, which leads to better solutions.
Missing functionality can be identified easily.
Confusing or difficult functions can be identified.
It allows developers and designers to present a visual and often interactive representation of the product to stakeholders for early feedback, validation of requirements, and identification of potential issues before significant development effort is invested.

17
Q

What are the key differences between the Prototype model and the Agile model in terms of development sequence and process flow?

A

Prototype Model:

Development Sequence & Process Flow:
The Prototype model typically starts with Requirement Gathering and Analysis, followed by a Quick Decision to Build a Prototype.

This prototype is then given for Customer Evaluation. Based on feedback, there’s Prototype Refinement (incorporating customer suggestions).

This cycle of building, evaluating, and refining the prototype can occur until the prototype is accepted.
Once the prototype is accepted, the Engineer Product phase begins, which involves the standard design, implementation, testing, and maintenance of the actual system, often following a more traditional iterative or waterfall-like approach for the final product development. The initial focus is on creating a discardable or evolvable model to clarify requirements.

Agile Model:

Development Sequence & Process Flow:
Agile development is inherently iterative and incremental.
It begins with Requirements Gathering (identifying business opportunities, planning time/effort, evaluating feasibility) and then Designing the Requirements (working with stakeholders, using user flow or UML diagrams).
The core of Agile is Construction/Iteration, where designers and developers work on the project to deploy a working product, which undergoes various stages of improvement, even with minimal functionality initially.
Each iteration typically involves a cycle of planning, design, development (Iterations, Demo & Feedback), Testing (QA team examines performance and bugs), and potentially Deployment of a working increment of the software.

Feedback is crucial after each iteration or release, and the team works through this feedback to inform subsequent iterations. The process flow is a continuous cycle of these activities, aiming for frequent delivery of functional software.

18
Q

Describe the differences between Architectural Design and Architectural View.

A

Architectural Design is concerned with understanding how a software system should be organized and designing the overall structure of that system. It is the critical link between design and requirements engineering, identifying the main structural components and their relationships. The output is an architectural model describing the system’s organization as a set of communicating components.

An Architectural View is a perspective used when designing and documenting a system’s architecture. Each architectural model shows only one view or perspective of the system, such as how it’s decomposed into modules, how run-time processes interact, or how components are distributed. Multiple views are usually needed for both design and documentation.

19
Q

Architectural abstraction is often split into two scopes: architecture in the small (software architecture) and architecture in the large (enterprise architecture). What are the main differences between the two architectures?

A

The main differences are:

Architecture in the small is concerned with the architecture of individual programs. At this level, the focus is on how an individual program is decomposed into components.

Architecture in the large is concerned with the architecture of complex enterprise systems that include other systems, programs, and program components. These enterprise systems are often distributed over different computers, which may be owned and managed by different companies.

20
Q

Based on the statements above, explain system analysis with three examples of the non-functional requirements.

A

The three advantages of having explicit architecture are:

Stakeholder communication
System analysis
Large-scale reuse
System analysis, in the context of an explicit architecture, means that it’s possible to analyze whether the system can meet its non-functional requirements. Having a defined architecture allows for evaluation against these quality attributes.

Three examples of non-functional requirements and how system analysis relates to them through architecture are:

  1. Performance: The architecture can be analyzed to see if critical operations are localized and communications are minimized. For instance, using large-grain components might be an architectural choice assessed for its impact on performance.
  2. Security: System analysis can examine if a layered architecture is used, with critical assets placed in the inner layers to enhance security.
  3. Maintainability: The architecture can be analyzed for the use of fine-grain, replaceable components, which supports easier maintenance.
21
Q

The Model-View-Controller (MVC) pattern separates presentation and interaction from the system data. The system is structured into three logical components that interact with each other.

(a)Explain the MVC pattern.
(b)Illustrate the MVC model based on (a).

A

The Model-View-Controller (MVC) pattern separates presentation and interaction from the system data. The system is structured into three logical components that interact with each other:

  • Model: This component manages the system data and the associated operations on that data. It encapsulates the application state.
  • View: This component defines and manages how the data is presented to the user. It renders the model and requests model updates.
  • Controller: This component manages user interaction (e.g., key presses, mouse clicks) and passes these interactions to the View and the Model. It maps user actions to model updates and selects the appropriate view.

The MVC pattern is used when there are multiple ways to view and interact with data, or when future requirements for interaction and presentation are unknown[cite: 71]. It allows data to change independently of its representation and supports presenting the same data in different ways.

(b) In CH9 ppt page 23

22
Q

Describe the generic layered architecture with an example of web-based systems (can choose any such as Shopee ecommerce).

A

A generic layered architecture organizes the system into a set of layers (or abstract machines), where each layer provides a set of services to the layer above it. The lowest-level layers represent core services likely used throughout the system. This structure supports the incremental development of sub-systems in different layers. When a layer interface changes, ideally only the adjacent layer is affected. It’s used when building new facilities on top of existing systems or when development is spread across teams.

Example: Layered Architecture for Shopee (E-commerce System)

While the provided PDF shows a generic layered architecture and an iLearn system, we can adapt this concept for an e-commerce platform like Shopee:

  1. User Interface Layer (Presentation Layer):

Components: Web browser interface, mobile app interface.
Functionality: Renders product listings, shopping cart, user profiles, order forms. Handles user input and displays information. For Shopee, this is what the customer directly interacts with – Browse products, adding to cart, viewing promotions.

  1. User Interface Management / Application Layer:

Components: User interface management, authentication and authorization, potentially some application-specific logic.
Functionality: Manages user sessions, validates user credentials, handles navigation logic, formats data for the UI. In Shopee, this layer would manage login sessions, check if a user is authorized to make purchases, and process UI requests like “show me trending products.” This layer might also include specific features like Shopee’s flash sales or voucher management.

  1. Core Business Logic / Domain Layer:

Components: Core business logic/application functionality.
Functionality: Implements the core e-commerce operations. This includes managing product catalogs, inventory, pricing rules, order processing, payment processing logic, recommendation algorithms, and shipping calculations. For Shopee, this is where the rules for a purchase transaction, stock updates after a sale, and eligibility for discounts are processed.

  1. System Utilities / Data Access Layer:

Components: System utilities, transaction management, database interaction.
Functionality: Provides access to data storage, manages database transactions (e.g., ensuring an order is fully committed or rolled back). Interacts with various databases for products, users, orders, etc. For Shopee, this layer handles all communication with the databases that store product details, customer accounts, and order histories.

  1. System Support (OS, Database, etc.) Layer:

Components: Operating System, Databases (e.g., SQL, NoSQL), external service integrations (payment gateways, logistics APIs).
Functionality: Provides the underlying infrastructure. The actual databases reside here, along with the operating systems running the servers and connections to third-party services that Shopee relies on.
This layered approach allows Shopee to develop and modify different aspects of its system independently. For instance, they could update the UI (Layer 1) without altering the core order processing logic (Layer 3).

23
Q

In a client-server architecture, describe the role of each of the following components:

A

a) Client:

Clients are users of the services provided by servers.
They access servers to make use of these services.
The client initiates requests to the server.
b) Server:

Servers are stand-alone components that provide specific services such as printing, data management, etc..
The functionality of the system is organized into services, with each service delivered from a separate server.
The server responds to client requests by providing the requested service or data.
c) Network:

The network allows clients to access servers.
It is the communication infrastructure that facilitates the exchange of requests and responses between clients and servers.

24
Q

List three uses of application architectures in software development

A

Three uses of application architectures in software development are:

  1. As a starting point for architectural design.
  2. As a design checklist.
  3. As a way of organising the work of the development team.
25
Evaluate two very widely used generic application architectures and give an example for each. [
1. Transaction Processing Systems: Evaluation: These systems process user requests for information from a database or requests to update the database. Users make asynchronous requests for service which are then processed by a transaction manager. They are data-centered applications that process user requests and update information in a system database. A generic architecture for these systems is often layered, including a user interface, user communications, information retrieval, and a system database. Example: E-commerce systems. For example, an online bookstore where users browse books, add them to a cart, and make purchases involves multiple transactions like querying book details, updating inventory, and processing payments. 2.Language Processing Systems: Evaluation: These systems accept a natural or artificial language as input and generate some other representation of that language. They may include an interpreter to act on the instructions in the language being processed. Their architecture typically includes a translator (with components like a lexical analyzer, syntax analyzer, semantic analyzer, and code generator) and an abstract machine that executes the generated language. Example: Compilers. For instance, a Java compiler takes Java source code (a formal language) as input, processes it through various stages like lexical analysis, syntax analysis, and code generation, and outputs bytecode (another representation) that can be executed by the Java Virtual Machine (an interpreter).
26
Describe three software product quality attributes.
Three software product quality attributes are: Reliability: This refers to the ability of a system or component to perform its required functions under stated conditions for a specified time. It emphasizes consistent performance and error-free operation. Availability: This is the proportion of time a system is functional and working. It takes into account uptime and system accessibility. Maintainability: This describes the ease with which a system can be updated, repaired, or enhanced. High maintainability helps reduce downtime and future development costs.
27
Explain the three underlying causes of program errors.
The three underlying causes of program errors are: Problem Understanding: Programmers make mistakes because they don't properly understand the problem or the application domain. This means the error originates from a misinterpretation of what the software is supposed to do. Technology Misuse: Programmers make mistakes because they use unsuitable technology or they don't properly understand the technologies used. This can include programming languages, libraries, databases, or IDEs. Implementation Slips: Programmers make mistakes because they make simple slips or they do not completely understand how multiple program components work together and change the program's state. These are errors introduced during the coding process itself.
28
Briefly describe the relationship between complexity and coupling
Complexity in a program increases with the number and nature of relationships between its elements. Coupling refers to how many connections or dependencies exist between these components. - High coupling signifies more connections or dependencies, leading to a system that is more complex and harder to manage. For instance, a node connected to six other nodes demonstrates high coupling and thus higher complexity. - Low coupling means fewer connections, resulting in a simpler system that is easier to maintain. Therefore, higher coupling directly contributes to increased program complexity.
29
Explain the two major programming principles.
Two major programming principles are: - Separation of Concerns: This principle states that each part of a program (such as a class or method) should handle a single, well-defined responsibility. It should cover all aspects of that concern in one place. For example, all authentication logic should be centralized and not scattered throughout the code. - Separate the 'What' from the 'How': This principle dictates that a component should expose only what is needed to use its service (the 'what'), while hiding the implementation details (the 'how') from users. For instance, a payment processing class should offer a method like processPayment(amount), but users do not need to know the internal validation processes or which APIs are called.
30
What is a design pattern in software development? Briefly describe how design patterns are used and explain the three main categories of design patterns.
A design pattern is a reusable solution to a common software design problem within a specific context. Design patterns translate programming principles into practical solutions for common design problems and focus on object-oriented concepts, describing solutions using objects and classes. They are not ready-made code but templates that must be adapted. How Design Patterns Are Used: Design patterns are used to: Improve communication: They provide a shared vocabulary (e.g., "Factory Method" or "Observer") that helps teams understand and discuss designs more effectively. Save time: Patterns offer ready-to-adapt templates that can speed up development. Avoid common pitfalls: They highlight best practices and trade-offs, which helps in avoiding poor design decisions. Enhance code quality: Patterns encourage principles like separation of concerns and loose coupling, leading to more robust systems. Three Main Categories of Design Patterns: Creational Patterns: These focus on flexible and abstract ways to create and initialize objects beyond basic language features. An example is the Singleton pattern, which ensures a class has only one instance. Structural Patterns: These describe how to organize and combine classes and objects into larger, reusable structures. The Adapter pattern, for instance, allows incompatible interfaces to work together. Behavioral Patterns: These explain how objects communicate, interact, and distribute tasks through message exchange. The Observer pattern lets objects be notified automatically when another object changes.
31
What is refactoring? Illustrate the process of refactoring.
Refactoring is the process of changing code to reduce its complexity without altering its external behavior. Over time, adding new code increases complexity, and without refactoring, code becomes harder to understand and maintain. It improves code readability and understandability, making it easier to modify and less error-prone when adding new features. Process of Refactoring (based on Figure 11.8): graph TD A[Start] --> B{Identify code 'smell'}; B --> C{Identify refactoring strategy}; C --> D[Make small improvement until strategy completed]; D --> E[Run automated code tests]; E --> C; C --> F[End when strategy is complete and tests pass]; 1. Start. 2. Identify code 'smell': Recognize areas in the code that suggest underlying problems (e.g., a very large class). 3. Identify refactoring strategy: Choose an appropriate technique to address the identified 'smell' and improve the code. 4. Make small improvement until strategy completed: Implement the refactoring in small, manageable steps. 5. Run automated code tests: After each small change, run tests to ensure the external behavior of the code remains unchanged. If tests fail, the changes might need to be reverted or fixed. 6. Repeat steps 3-5 until the refactoring strategy is fully implemented and the code is improved.
32
List three complexity reduction guidelines for refactoring with one related example.
Three complexity reduction guidelines that can be applied during refactoring are: - Structural Complexity Reduction: Break down long classes or functions into smaller, more focused units to improve cohesion and readability. Example: If a DeviceInventory class handles both managing device data (laptops, tablets, phones, assignments) and printing inventory reports, it violates the Single Responsibility Principle. During refactoring, you would separate the printing functionality into a new InventoryReport class. - Decision Complexity Reduction: Replace deeply nested if-then-else statements with simpler structures like guard clauses. Example: A function agecheck that uses multiple nested if-else statements to determine an insurance premium multiplier based on age and experience (Program 11.1 from the PDF) can be refactored. The refactored version, agecheck_with_guards (Program 11.2 from the PDF), uses guard clauses to handle specific cases early, reducing nesting and improving clarity. - Data Complexity Reduction: Simplify your data structure. While the PDF mentions guidelines like using clear interfaces for abstract components and avoiding data aliases for new code, these are also applicable during refactoring. Example: If a program uses different names (aliases) for the same piece of data across various modules, this increases data complexity and can lead to confusion. Refactoring would involve identifying these aliases and consolidating them to use a single, consistent, and clear name for that data element throughout the program.