Structural Design Patterns
Explore the key structural design patterns that help organize classes and objects in software design. This lesson covers patterns like Decorator for dynamic functionality, Facade for simplified interfaces, Adapter for compatibility, Bridge for independent variation, Composite for hierarchical structures, Flyweight for data sharing, and Proxy for access control. You will understand when and how to apply these patterns to improve system flexibility and maintainability.
Introduction to structural patterns
In this lesson, we will discuss structural design patterns. As the name implies, these patterns are concerned with object relationships and the structure of classes or objects. They help to add new functionality without having to modify the entire system. They ensure that if one part of a system changes, the whole system does not change with it. Let’s look at the most common structural patterns that are used in solving design problems.
Decorator pattern
The Decorator pattern focuses on adding properties, functionalities, and behavior to existing classes dynamically. The additional decoration functionalities aren’t considered essential enough to be a part of the original class definition since they can cause clutter. Hence, the Decorator pattern lets us modify the code without changing the original class.
Unlike creational patterns, the Decorator pattern is a structural pattern that does not focus on object creation but rather on decoration. Hence, it doesn’t rely on prototypal inheritance alone. It takes the object and keeps adding decoration to it. This makes the process more streamlined. Let’s look at an example to understand this concept better.
The illustration below shows that ice-cream toppings can be a part of the Decorator pattern for ...