5 and 6
5 and 6
used to improve the internal structure of code Costs: The costs of implementing operations
without altering its external behavior. It include not only computational resources but
involves making incremental changes to the also development time, complexity, and
codebase to enhance its readability, maintenance overhead. Choosing algorithms
maintainability, and extensibility, while that minimize these costs ensures that the
reducing complexity. Refactoring aims to software is efficient to run, straightforward to
making it easier to understand, modify, and develop, and easy to maintain.
extend in the future. Process: Identification: Considerations: When selecting algorithms,
Developers identify areas of the codebase factors such as must be taken into account.
that could benefit from refactoring. This may It's essential to balance the trade-offs
include sections with complex logic, between different approaches and choose
duplicated code, or poor design. Analysis: the one that best fits the specific
They analyze the identified areas to requirements 2) Select data structures
understand the underlying issues and appropriate to the algorithms : Algorithms
determine the best approach for refactoring. need data structures to work with efficiently.
Planning: A plan is devised for implementing During analysis, you focused on the logical
the refactoring changes, considering factors structure of the system, but during design,
like impact on existing functionality, testing you create data structures that help
requirements, and potential risks. Execution: algorithms work well. These data structures
Developers implement the planned changes, don't add new information but help organize
making careful adjustments to the code while existing data effectively. Examples of data
ensuring that external behavior remains structures include arrays, lists, trees, and
unchanged. Testing: After refactoring, sets, which are often part of the language's
thorough testing is performed to validate that standard libraries. 3) Define new internal
the code still behaves as expected and that classes and operations. Sometimes, new
no unintended side effects have been low-level operations are needed when
introduced. Documentation: Documentation breaking down high-level operations. During
is updated to reflect the refactored code, algorithm expansion, new classes might be
ensuring that other developers understand created to hold intermediate results. These
the changes made and their rationale. internal classes and operations may not be
mentioned in the original problem description
Designing Algorithms: To design but are created to support the design.
algorithms we need to perform the following Example: In a banking system, when
steps: 1) Choose algorithms that minimize implementing a transaction processing
the cost of implementing operations. 2) operation, new internal classes like
Select data structures appropriate to the TransactionRecord may be created to hold
algorithms. 3) Define new internal classes intermediate transaction details, such as
and operations as necessary. 4) Assign transaction amount, date, and involved
operations to appropriate classes. 1) Choose accounts.
algorithms that minimize the cost of Design Optimization: Design optimization
implementing operations : Efficiency: The involves refining the structure and algorithms
efficiency of an algorithm refers to Algorithms of a system to improve its efficiency while
that minimize costs typically execute quickly maintaining its functionality. Key Features: 1)
and consume fewer resources. Provide efficient access paths: 2) Rearrange
Effectiveness: An effective algorithm the computation for greater efficiency: 3)
accomplishes its intended purpose It Save intermediate results to avoid
produces correct results and handles edge recomputation: 1) Provide efficient access
paths: This involves organizing the defining methods and functions that
relationships between classes to optimize encapsulate the behaviour required to fulfill
access to information. For example, in a each use case. 3) Designing an Algorithm: At
company's employee skills database, this stage, you delve into the specifics of how
arranging associations to quickly find each operation will be implemented. This
employees with specific skills can improve includes selecting appropriate algorithms
performance. Example: 1) In the employee and data structures to efficiently perform the
skills database, using a hashed set for required tasks. It's about designing the logic
storing skills can reduce the number of tests that will drive the behavior of the system. 4)
required to find employees with a particular Recurse Downward to Design Operations
skill. 2) Rearrange the computation for that Support Higher-level Operations: This
greater efficiency: Optimizing the sequence step involves breaking down complex
of operations can enhance performance. It's operations into simpler, more manageable
beneficial to eliminate dead paths early and components. It's about decomposing tasks
narrow down searches as soon as possible. into smaller units of work, which can then be
Sometimes, reversing the execution order of implemented as methods or functions within
loops can improve efficiency. Example: the relevant classes. 5) Refactor the Model
Suppose we have an online shopping for a Cleaner Design: to improve its clarity,
platform where customers can browse maintainability, and extensibility. This might
products, add them to their cart, and proceed involve renaming classes or methods,
to checkout. During the checkout process, simplifying complex relationships, or
various checks and calculations need to be reorganizing the overall architecture to
performed, including verifying payment enhance readability and modularity. 6)
details, applying discounts, and calculating Designing Optimization: Here, the focus is on
shipping costs. 3) Save intermediate results optimizing the design to minimize execution
to avoid recomputation: Caching derived time, memory usage, and other resource
attributes or values can prevent the need for costs. This might involve fine-tuning
repeated computation. Updates to source algorithms, optimizing data structures, or
attributes should trigger updates to derived introducing caching mechanisms to improve
attributes to maintain consistency. Different performance
strategies like explicit update, periodic
recomputation, or active values can be used Recursing Downward: Recursing downward
to manage updates. in the context of software design refers to the
process of breaking down high-level system
Class design involves the following functionality or operations into smaller, more
steps: 1) Bridge the Gap from High-level detailed components or mechanisms. This
Requirements to Low-level Services: This process typically starts from the top, with
step involves translating the high-level higher-level operations being decomposed
requirements captured during analysis into into lower-level ones, resulting in a
more detailed specifications that can be hierarchical structure of operations or
implemented at a lower level. It's about functionalities. Recursing downward can be
identifying the core functionalities and done in two main ways: functionality layers
services that the system must provide. 2) and mechanism layers
Realize Use Cases with Operations: Use -----------------------------------------------------------
cases represent interactions between the
system and its users. In this step, you map
out these interactions into operations that the
system's classes will perform. This involves
Application Class Model (ACM) is a main categories of control flow: external
representation of the classes and their control and internal control. 1) External
relationships within an application domain. It Control: A) Procedure-Driven Sequential
provides a high-level view of the classes Control: In this approach, the flow of control
involved in the system, along with their is managed by the sequential execution of
attributes, methods, and associations. procedures or functions. Each procedure
executes sequentially, and the program
1. **Classes**: Classes represent the
waits for external input before proceeding to
fundamental building blocks of an
the next step. B) Event-Driven Sequential
application. Each class encapsulates a set
Control: In event-driven systems, control is
of related attributes (data) and methods
managed by an event dispatcher or monitor.
(functions or procedures) that define its
Application procedures are attached to
behavior..2. **Attributes**: Attributes are the
specific events, and the dispatcher calls
data elements associated with a class. They
these procedures when the corresponding
describe the characteristics or properties of
events occur. C) Concurrent Control: In
objects belonging to that class. Attributes
concurrent control, multiple independent
are represented within classes as named
tasks or processes run simultaneously.
slots or fields. 3. **Methods**: Methods
Each task can execute concurrently with
define the behavior of a class. They
others, and communication between tasks is
represent the operations or actions that
typically achieved through message
objects of the class can perform. Methods
passing. 2) Internal Control: Internal control
may manipulate the class's attributes,
refers to the flow of control within a single
interact with other objects, or perform
process or task. Unlike external events,
computations. 4. **Relationships**:
which involve interactions between different
Relationships describe how classes are
objects or components, internal control
connected or interact with each other.
focuses on the execution flow within a single
Common types of relationships include
process. Common internal control
associations, generalization (inheritance),
mechanisms include: A) Procedure Calls:
aggregation, and composition. Associations
Sequential execution of procedures within a
represent connections between classes,
single process. B) Quasi-Concurrent
while generalization represents a "is-a"
Intertask Calls: Quasi-concurrent intertask
relationship (inheritance) between a
calls are like a trick in programming that
superclass and its subclasses. 5.
makes it seem like different tasks are
**Multiplicity**: Multiplicity specifies the
happening at the same time, C) Concurrent
number of instances of one class that are
Intertask Calls: These involve concurrent
associated with instances of another class
execution of tasks within a single process,
in a particular relationship .6.
where communication between tasks is
**Constraints**: Constraints are additional
managed internal.
rules or conditions that apply to classes,
attributes, methods, or relationships. They i) Libraries:Libraries in Object-Oriented
specify constraints on the data or behavior Analysis and Design (OOAD) are collections
of the system, ensuring its correctness and of reusable code modules or components
integrity. that provide prewritten functionality to be
used in software development. They
typically contain functions, classes, data
Choosing a Software Control Strategy: In structures, and other resources that can be
software systems, control flow refers to how easily integrated into applications to perform
the flow of operations and events is specific tasks or implement certain
managed within the system. There are two functionalities. ii) Frameworks:
Frameworks in OOAD are comprehensive but random-access files and indexed files
sets of pre-designed software components, may have different commands and storage
libraries, and tools that provide a structured formats. 3) Databases: Databases are
approach to building applications or systems managed by Database Management
within a specific domain or platform. Systems (DBMSs) and offer a more
Frameworks typically offer a skeleton structured and organized way to store and
architecture, reusable code modules, and retrieve data. They come in various types,
predefined patterns for solving common including relational .
problems, allowing developers to focus on
How to Handle Global Resources:
implementing application-specific logic
Handling global resources involves
rather than dealing with low-level details.
identifying global resources and
Patterns in OOAD refer to recurring implementing mechanisms to control access
solutions to common design problems to those resources in a system: 1) Identify
encountered during software development. Global Resources: Determine what
They capture best practices, principles, and resources in your system are global,
proven techniques for designing and meaning they are shared and accessed by
implementing software systems in a multiple components or processes. These
reusable and scalable manner. Patterns can include physical units like processors or
help developers address design challenges, communication devices, space like disk
improve code quality, and promote space. 2) Establish Access Control
maintainability and flexibility in software Mechanisms: Once identified, establish
systems. Patterns can be classified into mechanisms to control access to these
several categories, including creational global resources. This ensures that multiple
patterns (e.g., Singleton, Factory Method), components or processes can use the
structural patterns (e.g., Adapter, resources without conflicting with each
Decorator), and behavioral patterns (e.g., other. 3) Use Guardian Objects for Logical
Observer, Strategy). Resources:A guardian object acts as a
gatekeeper, regulating access to the
Management of Data Storage: In
resource and preventing conflicts. All
managing data storage for a system, there
access to the resource should pass through
are several alternatives to consider, each
the guardian object. 4) Consider Resource
with its own advantages and key features:
Partitioning: Resource partitioning involves
1) Data Structures: Data structures refer to
dividing global resources into logical
the way data is organized and stored in
subsets and assigning each subset to
memory, typically using programming
different guardian objects for independent
language constructs like arrays, linked lists,
control.. 5) Implement Locking Mechanisms:
or trees. Data structures like arrays, linked
In time-critical applications where passing
lists, or trees are commonly used in memory
access through a guardian object is too
for efficient data manipulation, they can also
costly, consider using locking mechanisms.
be adapted for persistent (long lasting)
Locks can be placed on subsets of the
storage. 2) Files: Files are a common and
resource, granting the lock holder the right
straightforward way to store data on disk.
to access the resource directly. 6) Avoid
They are relatively inexpensive, simple to
Direct Access Unless Necessary: Direct
use, and provide permanent storage. Files
access to shared resources should be
can store data in various formats, including
avoided unless absolutely necessary,
plain text, binary, or structured formats like
especially in time-critical scenarios. This
JSON or XML. Sequential files, where data
helps prevent conflicts and ensures proper
is stored in a linear sequence, are standard,
control over resource usage
-----------------------------------------------------------