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.
Creational Patterns: Focus: These patterns concern themselves with the process of object creation. Characteristics
Decouple the system from specific classes it creates.
Hide the intricacies of creating and representing objects.
Provide mechanisms to create objects based on requirements, rather than explicit instantiation.
Common Patterns: Singleton, Factory Method, Abstract Factory, Builder, Prototype.
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
Emphasize the composition of classes or objects.
Focus on ensuring that different components of a system can work together efficiently.
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.
Behavioral Patterns: Focus: Primarily concerned with communication between objects, these patterns define how entities interact and distribute responsibilities.
Characteristics
Define the roles that objects play in communication and interaction.
Focus on ensuring object collaborations are defined and manageable.
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
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.
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.
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:
Adapter: Adapts one interface for a class into one that a client expects
Bridge: Decouple an abstraction from its implementation so that the two can vary independently
Composite: A tree structure of objects where every object has the same interface
Decorator : Add additional functionality to a class at runtime where subclassing would result in an exponential rise of new classes
Facade: Create a simplified interface of an existing interface to ease usage for common tasks
Flyweight: A high quantity of objects share a common properties object to save space
Proxy: A class functioning as an interface to another thing
Sub-Patterns
Aggregate: A version of the Composite pattern with methods for aggregation of children
Extensibility: also known as Framework - hide complex code behind a simple interface
Pipes and filters: A chain of processes where the output of each process is the input of the next
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.
Ad Gang of Four Patterns
Figure 3.1 provides a visualization of the Structural design patterns.
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.