What are Structural Patterns?
Structural patterns are mostly concerned with object composition or in other words how the entities can use each other. They help in answering “How to build a software component?”
Wikipedia Definition
In software engineering, structural design patterns are design patterns that ease the design by identifying a simple way to realize relationships between entities.
The Seven Structural Patterns
This section covers all seven structural design patterns:Adapter
Wrap an incompatible object to make it compatible with another class
Bridge
Prefer composition over inheritance by separating abstraction from implementation
Composite
Treat individual objects and compositions uniformly
Decorator
Dynamically add behavior to objects at runtime
Facade
Provide a simplified interface to a complex subsystem
Flyweight
Minimize memory usage by sharing data with similar objects
Proxy
Represent the functionality of another class with additional logic
Key Concepts
Object Composition
Structural patterns focus on how classes and objects are composed to form larger structures. They use inheritance to compose interfaces and define ways to compose objects to obtain new functionality.Flexibility and Efficiency
These patterns help ensure that if one part of a system changes, the entire structure doesn’t need to change. They make it easier to modify the structure independently of the components themselves.When to Use Structural Patterns
Use structural patterns when you need to:
- Simplify complex relationships between objects
- Add functionality to objects without modifying their structure
- Create flexible and reusable object compositions
- Provide alternative interfaces to existing classes
Next Steps
Explore each pattern in detail to understand:- Real-world examples
- Implementation details
- When to use each pattern
- PHP code examples