Structural Design Patterns
Structural design patterns deal with the composition of classes and objects to form larger, flexible, and efficient structures.
List of Main Structural Design Patterns
-
Adapter Pattern
Allows incompatible interfaces to work together.- Example: Adapting a legacy class to a new interface.
-
Decorator Pattern
Adds behavior or responsibilities to individual objects dynamically.- Example: Adding scrollbars to a window.
-
Facade Pattern
Provides a simplified interface to a complex subsystem.- Example: A single entry point for a set of APIs.
-
Flyweight Pattern
Reduces memory usage by sharing common parts of objects.- Example: Text formatting in a document editor.
Summary Table
| Pattern | Intent | Example Use Case |
|---|---|---|
| Adapter | Make incompatible interfaces work together | Payment gateway integration |
| Decorator | Add responsibilities to objects dynamically | Pizza toppings, UI enhancements |
| Facade | Simplify interface to a complex subsystem | Home theater system, API gateway |
| Flyweight | Share objects to minimize memory usage | Forest of trees |