Structural Design Patterns

Shadman Jamil
4 min readFeb 24, 2022

--

Structural patterns are concerned with how classes and objects are composed to form larger structures. Structural class patterns use inheritance to compose interfaces or implementations

  • Composite Pattern [A tree structure of simple and composite objects]

This pattern is used when we need to treat a group of objects similarly to a single object. Composite pattern composes objects in terms of a tree structure to represent part as well as a whole hierarchy.

In simple words, this pattern creates a class that contains a group of its objects. This class provides ways to modify its group of the same objects.

  • Adapter Pattern [Match interfaces of different classes]

This design pattern works as a bridge between two incompatible interfaces. This type of design pattern comes under a structural pattern, as this pattern combines the capability of two independent interfaces.

You can create an adapter. This is a special object that converts the interface of one object so that another object can understand it.

An adapter wraps one of the objects to hide the complexity of conversion happening behind the scenes. The wrapped object isn’t even aware of the adapter.

  • Bridge Pattern [Separates an object’s interface from its implementation]

This design pattern lets you split a large class or a set of closely related classes into two separate hierarchies; abstraction and implementation, which can be developed independently of each other.

This pattern is used when we need to decouple an abstraction from its implementation so that the two can vary independently. This type of design pattern comes under structural pattern, as this pattern decouples the implementation class and abstract class by providing a bridge structure between them.

  • Decorator Pattern [Add responsibilities to objects dynamically]

This design pattern allows a user to add new functionality to an existing object without altering its structure. This type of design pattern comes under a structural pattern as this pattern acts as a wrapper to the existing class.

This pattern creates a decorator class that wraps the original class and provides additional functionality, keeping the class method's signature intact.

In simple words, this pattern lets you attach new behaviors to objects by placing these objects inside special wrapper objects that contain the behaviors.

  • Facade Pattern [A single class that represents an entire subsystem]

This pattern provides a simplified interface to a library, a framework, or any other complex set of classes.

It hides the complexities of the system and provides an interface to the client using which the client can access the system. This type of design pattern comes under a structural pattern, as this pattern adds an interface to the existing system to hide its complexities.

  • Proxy Pattern [An object representing another object]

This design pattern lets you provide a substitute or placeholder for another object. A proxy controls access to the original object, allowing you to perform something either before or after the request gets through to the original object.

In this pattern, a class represents the functionality of another class. This type of design pattern comes under a structural pattern.

  • Flyweight Pattern [A fine-grained instance used for efficient sharing]

Flyweight pattern is primarily used to reduce the number of objects created and decrease memory footprint and increase performance. This type of design pattern comes under structural pattern as this pattern provides ways to decrease object count thus improving the object structure of the application.

In simple words, this pattern lets you fit more objects into the available amount of RAM by sharing common parts of the state between multiple objects instead of keeping all the data in each object.

This pattern also suggests that you stop storing the extrinsic state inside the object. Instead, you should pass this state to specific methods which rely on it. Only the intrinsic state stays within the object, letting you reuse it in different contexts. As a result, you’d need fewer of these objects since they only differ in the intrinsic state, which has much fewer variations than the extrinsic.

Cheers!

--

--

Shadman Jamil

Tech Savvy, Software Architect, Mentor, and Entrepreneur