Comparisons Unit -3

Architectural Patterns

1. Core Focus

Architecture

Core Focus

Data-Centered

Centralized data storage and access. Components interact via a shared data repository.

Data Flow

Flow of data through a pipeline of processing components.

Call and Return

Hierarchical control flow through subroutine calls.

Object-Oriented

Modeling the system as interacting objects with encapsulated data and behavior.

Layered

Organizing the system into layers, each providing services to the layer above.


2. Communication Pattern

Architecture

Communication Pattern

Data-Centered

Components communicate indirectly through a shared data store.

Data Flow

Data flows sequentially from one component to the next in a pipeline.

Call and Return

Direct communication via subroutine calls and returns.

Object-Oriented

Objects communicate via method calls and messages.

Layered

Communication is restricted to adjacent layers (e.g., Layer N talks to Layer N+1).


3. Modularity

Architecture

Modularity

Data-Centered

Moderate. Components are independent but tightly coupled to the data store.

Data Flow

High. Each component in the pipeline is modular and independent.

Call and Return

High. Subroutines are modular but can become nested and complex.

Object-Oriented

Very High. Objects encapsulate data and behavior, promoting reusability.

Layered

High. Each layer is modular but tightly coupled to adjacent layers.


4. Scalability

Architecture

Scalability

Data-Centered

Limited by the central data store. Can scale by adding more components.

Data Flow

Scalable for linear pipelines but can become complex with branching flows.

Call and Return

Limited. Deeply nested calls can become a bottleneck.

Object-Oriented

Highly scalable due to encapsulation and loose coupling.

Layered

Scalable but can introduce overhead due to inter-layer communication.


5. Performance

Architecture

Performance

Data-Centered

Can suffer from bottlenecks due to centralized data access.

Data Flow

Efficient for linear processing but can introduce latency in long pipelines.

Call and Return

Efficient for small systems but can degrade with deep call stacks.

Object-Oriented

Can introduce overhead due to object management and polymorphism.

Layered

Can introduce overhead due to inter-layer communication.


6. Complexity

Architecture

Complexity

Data-Centered

Low to Moderate. Easy to understand but can become complex with many components.

Data Flow

Moderate. Simple for linear flows but complex for branching or cyclic flows.

Call and Return

Low to Moderate. Simple for small systems but can become complex with nesting.

Object-Oriented

High. Requires careful design to manage object interactions and hierarchies.

Layered

Moderate. Easy to understand but can become complex with many layers.


7. Flexibility

Architecture

Flexibility

Data-Centered

Low. Changes to the data store can impact all components.

Data Flow

Moderate. Easy to add/remove components but changes to flow can be complex.

Call and Return

Moderate. Easy to add subroutines but changes to control flow can be tricky.

Object-Oriented

High. Objects can be easily extended or modified using inheritance and polymorphism.

Layered

Moderate. Changes to one layer can impact adjacent layers.


8. Use Case Suitability

Architecture

Best For

Worst For

Data-Centered

Systems requiring shared data access (e.g., banking, inventory management).

High-performance systems or systems with low data sharing.

Data Flow

Stream processing (e.g., video encoding, ETL pipelines).

Systems with complex data dependencies or real-time requirements.

Call and Return

Small to medium systems with sequential tasks (e.g., calculators, scripts).

Large, complex systems or systems requiring concurrency.

Object-Oriented

Complex systems with many interacting entities (e.g., e-commerce, games).

Simple systems or performance-critical applications.

Layered

Systems requiring separation of concerns (e.g., web applications, OS design).

Systems where performance is critical or layers introduce unnecessary overhead.


9. Example Systems

Architecture

Example Systems

Data-Centered

Banking systems, inventory management systems.

Data Flow

Video processing pipelines, ETL systems.

Call and Return

Simple calculators, batch processing scripts.

Object-Oriented

E-commerce platforms, video games, simulation systems.

Layered

Web applications (UI, business logic, database), operating systems.


10. Key Strengths and Weaknesses

Architecture

Strengths

Weaknesses

Data-Centered

Centralized data management, consistency.

Single point of failure, performance bottlenecks.

Data Flow

Modular, easy to process data streams.

Complex flows can become hard to manage.

Call and Return

Simple, easy to implement for small systems.

Not scalable, difficult to manage for large systems.

Object-Oriented

Reusability, encapsulation, extensibility.

Overhead, complexity in design.

Layered

Separation of concerns, abstraction, interoperability.

Performance overhead, tight coupling between layers.


Minute Comparisons:

  • Data-Centered is ideal for systems with shared data but suffers from centralization issues.

  • Data Flow excels in stream processing but struggles with complex dependencies.

  • Call and Return is simple and effective for small systems but lacks scalability.

  • Object-Oriented is powerful for complex systems but introduces overhead.

  • Layered promotes separation of concerns but can introduce performance overhead.

Each architecture has its niche, and the choice depends on the specific requirements of the system being developed.


Coupling

Detailed Comparison of Coupling Types in Software Architecture

Type of Coupling

Definition

Strength of Coupling

Implications

Desirability

Best Practices

Content Coupling

Direct modification of another module's internal data.

Highest

Breaks encapsulation, system fragility.

Least desirable.

Avoid direct access to internal data; use getters/setters or public interfaces.

Common Coupling

Sharing global data, such as global variables.

Strong

Hidden dependencies, scalability issues.

Undesirable.

Minimize global variables; use local variables or dependency injection.

Routine Call Coupling

Modules interact through function calls with well-defined parameters.

Moderate

Manageable if interfaces are well-defined.

Acceptable if managed properly.

Use stable interfaces; consider dependency inversion for loose coupling.

Control Coupling

One module controls another's flow via flags or similar mechanisms.

Stronger than data coupling, weaker than content/common

Complexity in flow control.

Less desirable due to complexity.

Use event-driven architectures or callbacks to reduce control dependencies.

Stamp Coupling

Sharing data structures and using different parts of them.

Moderate

Dependencies on structure format.

Undesirable due to format dependencies.

Use DTOs or encapsulate data structures to minimize sharing.

Data Coupling

Exchange data through well-defined interfaces, such as parameters or return values.

Weakest

Minimizes dependencies, enhances maintainability and scalability.

Most desirable.

Design interfaces with abstract data types or service contracts.

Additional Considerations:

  1. Encapsulation and Information Hiding:

    • Content coupling violates these principles, leading to a brittle system. Proper encapsulation ensures that modules interact only through well-defined interfaces.

  2. Global State and Side Effects:

    • Common coupling through global variables can lead to unintended side effects and make debugging challenging. Avoid global state whenever possible.

  3. Interface Stability:

    • Routine call coupling benefits from stable and well-defined interfaces. Regularly review and refactor interfaces to maintain stability.

  4. Testing Implications:

    • High coupling makes unit testing difficult, often leading to more integrated tests. Strive for loose coupling to facilitate independent testing.

  5. Performance Trade-offs:

    • Tighter coupling might offer performance benefits but at the cost of maintainability. Balance performance needs with architectural principles.

  6. Modern Programming Practices:

    • Utilize tools like static code analyzers to detect high coupling. Employ design patterns such as Strategy or Observer to promote loose coupling.

  7. Architectural Styles:

    • Layered architectures may exhibit routine call coupling between layers, while object-oriented architectures might favor data coupling through method invocations.


Cohesion

Cohesion Types in Software Architecture: Detailed Explanation and Comparison

Cohesion

Definition

Strength

Example

Desirability

Best Practices

Functional Cohesion

Elements grouped because they contribute to a single, well-defined function.

Strongest

A module that calculates the total price of items in a shopping cart.

Most desirable

Group elements with a clear, single purpose.

Procedural Cohesion

Elements grouped because they follow a specific sequence of operations.

Strong

A module for user registration: validation, database insertion, email.

Desirable

Keep operations in sequence but with clear separation of concerns.

Sequential Cohesion

Elements grouped because the output of one is the input to another.

Strong

A data processing pipeline where each function processes the previous one.

Desirable

Design processes in a logical flow with clear input-output dependencies.

Communicational Cohesion

Elements grouped because they work with the same data or entity.

Moderate

A module interacting with an API using the same data formats and protocols.

Moderate

Group operations that use the same data or interact with the same external service.

Informational Cohesion

Elements grouped because they operate on the same information or data.

Moderate

A module that handles all operations related to customer data.

Moderate

Keep related operations together when they work with the same data set.

Logical Cohesion

Elements grouped due to a logical relationship, even if unrelated in function.

Weaker

A module containing various utility functions like string manipulations.

Undesirable

Avoid grouping unrelated functions, separate them for clarity.

Temporal Cohesion

Elements grouped because they execute close in time.

Moderate

A module handling all startup initialization tasks in an app.

Moderate

Group related time-based tasks together for better organization.

Collision Cohesion

Elements grouped due to unintended dependencies or resource conflicts.

Weakest

A module accidentally sharing a global variable with another module.

Least desirable

Avoid resource conflicts and unintended dependencies.

Conclusion and Best Practices:

  • Desirability: Aim for high cohesion types like functional and sequential for robust, maintainable software.

  • Avoidance: Minimize weaker cohesion types like logical and collision to ensure modules are easier to maintain and less prone to bugs.

  • Design Implications: Higher cohesion improves software understandability, maintainability, and reusability. Lower cohesion may lead to difficulty in debugging and system instability.

Communicational vs. Informational Cohesion

Aspect

Communicational Cohesion

Informational Cohesion

Focus

Focuses on interactions with external entities or data sources. Concerned with data exchange and protocols.

Centers on processing internal data, grouping functionalities that handle the same type of data.

Scope

Involves data exchange protocols and formats with external systems, focusing on communication aspects.

Involves operations on a specific set of internal data, centralizing data-related operations.

Examples

A module handling all API calls to a specific external service, managing data formats and protocols.

A module managing all operations related to employee records in an internal database, ensuring data integrity.

Implications

Facilitates easier changes to internal data structures without affecting external communications.

Enhances data management efficiency and reduces errors by centralizing data operations.

Design Principles

Supports separation of concerns and the single responsibility principle in managing external interactions.

Supports the single responsibility principle in managing internal data processing.

Maintainability

Changes to external communication protocols require less modification to internal logic.

Centralized data management leads to reduced redundancy and better data consistency.

Scalability

Facilitates the integration of new external systems or protocols without major changes to internal functionality.

Facilitates better data integrity as internal data operations are clearly grouped, ensuring scalability.

Conclusion:

  • Communicational Cohesion is important for managing interactions with external systems, ensuring that changes to communication protocols do not affect the system's internal functionality.

  • Informational Cohesion is crucial for maintaining consistent, reliable operations with internal data, improving system efficiency and reducing redundancy.