Structural Patterns  «Prev  Next»

Delineating Structural Design Patterns: A Comparative Analysis with Behavioral and Creational Patterns

In software design, patterns are codified solutions to recurring problems. These patterns, famously consolidated by the Gang of Four (GoF) in their seminal book "Design Patterns: Elements of Reusable Object-Oriented Software," can be categorized into three principal groups: Creational, Structural, and Behavioral. Each category addresses a specific facet of object creation, composition, and interaction. To fully grasp the nuances and distinctiveness of Structural Design Patterns, it's imperative to juxtapose them against their Creational and Behavioral counterparts.
  1. Creational Patterns: Focus: These patterns concern themselves with the process of object creation.
    Characteristics
    1. Decouple the system from specific classes it creates.
    2. Hide the intricacies of creating and representing objects.
    3. Provide mechanisms to create objects based on requirements, rather than explicit instantiation.
    Common Patterns: Singleton, Factory Method, Abstract Factory, Builder, Prototype.
  2. Structural Patterns: Focus: The heart of Structural Patterns lies in establishing relationships between entities, ensuring they are pieced together to form larger structures in a streamlined manner.
    Characteristics
    1. Emphasize the composition of classes or objects.
    2. Focus on ensuring that different components of a system can work together efficiently.
    3. Often address the 'how': how different elements of a system are structured, ensuring scalability, flexibility, and maintainability.
    Common Patterns: Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy.
  3. Behavioral Patterns: Focus: Primarily concerned with communication between objects, these patterns define how entities interact and distribute responsibilities.
    Characteristics
    1. Define the roles that objects play in communication and interaction.
    2. Focus on ensuring object collaborations are defined and manageable.
    3. Emphasize on the distribution of responsibilities and the dynamic interplay between objects.

    Common Patterns: Observer, Strategy, Command, Iterator, Mediator, Memento, State, Template Method, Visitor, Chain of Responsibility, Interpreter.


Differentiating Factors

  1. Nature of Concern: While Creational Patterns revolve around the instantiation process, Structural Patterns are all about composition and ensuring different parts of the system fit together cohesively. Behavioral Patterns, on the other hand, address the dynamic interplay and communication mechanisms among objects.
  2. Level of Abstraction: Creational Patterns often operate at a level abstracted from the concrete classes in the system. Structural Patterns deal with a slightly higher level, focusing on how groups of objects or classes collaborate to form larger structures. Behavioral Patterns, meanwhile, operate at the highest level of abstraction, concentrating on wide-scale interactions and collaborations between objects.
  3. Systemic Impact: The modifications in a Creational Pattern primarily impact the instantiation process. Alterations in Structural Patterns might necessitate changes in the system's structure or the inter-relationships between its components. Modifications in Behavioral Patterns could reshape the very dynamics of object interactions and responsibilities.

While each category of the GoF patterns addresses a specific set of concerns, their true power is unleashed when they are used synergistically. Structural Design Patterns, by emphasizing composition and arrangement, act as the architectural glue, ensuring that the components instantiated by Creational Patterns can efficiently interact and communicate as elucidated by the Behavioral Patterns.
In software engineering, structural design patterns are design patterns that ease the design by identifying a simple way to realize relationships between entities. Structural patterns are for tying together existing function.
Examples of Structural Patterns include:
  1. Adapter: Adapts one interface for a class into one that a client expects
  2. Bridge: Decouple an abstraction from its implementation so that the two can vary independently
  3. Composite: A tree structure of objects where every object has the same interface
  4. Decorator : Add additional functionality to a class at runtime where subclassing would result in an exponential rise of new classes
  5. Facade: Create a simplified interface of an existing interface to ease usage for common tasks
  6. Flyweight: A high quantity of objects share a common properties object to save space
  7. Proxy: A class functioning as an interface to another thing

Gang of Four Patterns

Sub-Patterns

  1. Aggregate: A version of the Composite pattern with methods for aggregation of children
  2. Extensibility: also known as Framework - hide complex code behind a simple interface
  3. Pipes and filters: A chain of processes where the output of each process is the input of the next
  4. Private class data: Restrict accessor/mutator access

  • Design phase
    The phase of a software project that concerns itself with the discovery of the structural components of the software system to be built, not with implementation details. Figure 3.1 provides a visualization of the Structural design patterns.
    Structural Patterns
    Figure 3.1: Structural patterns focus on creating new structures from existing ones

    The focal points for Structural design patterns lie in creating new structures without destroying the old ones. On top of that, the standard of loose coupling for reuse and change are both maintained and enhanced in the Structural patterns.

Aggregate Design Pattern

The term "Aggregate pattern" is not commonly recognized as a standalone design pattern in traditional software design pattern literature (such as the original Gang of Four patterns or classic pattern catalogs).
However, the term "aggregate" has significant meaning within software engineering, particularly in two well-known contexts: 1. Domain-Driven Design (DDD) In Eric Evans' Domain-Driven Design, an Aggregate is a central concept that:
  • Represents a cluster of domain objects treated as a single unit.
  • Acts as a boundary for transactional consistency.
  • Usually has a single root entity (Aggregate Root) through which all interactions with the aggregate must occur.
Characteristics of DDD Aggregates:
  • Aggregate Root: A specific entity that serves as the entry point and guardian for the integrity of the entire aggregate.
  • Consistency Boundary: Transactions affecting multiple objects in the aggregate must maintain consistency internally. External code interacts only through the aggregate root.
  • Encapsulation: Aggregates encapsulate internal state and enforce invariants within the domain.

Example:
Consider a simplified e-commerce example:
  • Order (Aggregate Root):
    • OrderID
    • Customer details
    • Payment info
  • Order Items (Entities within aggregate):
    • Product
    • Quantity
    • Price

In this scenario, the Order object is the aggregate root, and the items are part of the aggregate. Interactions (such as adding, removing, or updating order items) are controlled via the aggregate root, ensuring consistency.
2. Aggregate as Structural Concept in Software Architecture
In general architectural terminology (not strictly DDD), an aggregate can simply refer to a grouping of related objects or data structures that should be managed or processed together for logical or performance reasons.
Conclusion: While "Aggregate pattern" isn't officially a standalone pattern like Singleton or Observer, the concept of an Aggregate is central to the practice of Domain-Driven Design, and understanding its role there is important for building robust, maintainable software.
If you're exploring design patterns specifically, focusing on aggregates within DDD would be your best reference point.

SEMrush Software 1 SEMrush Banner 1
.