The Wayback Machine - https://web.archive.org/web/20240709014818/https://www.geeksforgeeks.org/structural-design-patterns/
Open In App

Structural Design Patterns

Last Updated : 19 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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

sdp-(1)

Consider how multiple inheritances mix two or more classes into one. The result is a class that combines the properties of its parent classes.

There are two recurring themes in these patterns:

  • This pattern is particularly useful for making independently developed class libraries work together.
  • Structural Design Patterns describe ways to compose objects to realize new functionality. The added flexibility of object composition comes from the ability to change the composition at run-time, which is impossible with static class composition.

Example for Structural Design Patterns

Consider an example, a drawing editor that lets users draw and arrange graphical elements (lines, polygons, text, etc.) into pictures and diagrams. The drawing editor’s key abstraction is the graphical object, which has an editable shape and can draw itself.

The interface for graphical objects is defined by an abstract class called Shape. The editor defines a subclass of the Shape for each kind of graphical object: a LineShape class for lines, a PolygonShape class for polygons, and so forth.

Types of Structural Design Patterns:

  • Adapter Method Design Patterns
  • Bridge Method Design Patterns
  • Composite Method Design Patterns
  • Decorator Method Design Patterns
  • Facade Method Design Patterns
  • Flyweight Method Design Patterns
  • Proxy Method Design Patterns

Adapter Method Design Patterns:

Adapter Method or Adapter Design Patterns also knows as wrapper. It convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.

When to use Adapter Method

  • You want to use an existing class, and its interface does not match the one you need.
  • You want to create a reusable class that cooperates with unrelated orunforeseen classes, that is, classes that don’t necessarily have compatible interfaces.
  • (object adapter only) you need to use several existing subclasses, but it’s unpractical to adapt their interface by subclassing every one. An object adapter can adapt the interface of its parent class.

Bridge Method Design Patterns

Bridge Method or Bridge Design Patterns also known as Handle/Body. Decouple an abstraction from its implementation so that the two can vary independently.

When to use Bridge Method

  • You want to avoid a permanent binding between an abstraction and its implementation. This might be the case,for example,when the implementation must be selected or switched at run-time.
  • Both the abstractions and their implementations should be extensible by subclassing. In this case, the Bridge pattern lets you combine the different abstractions and implementations and extend them independently.
  • Changes in the implementation of an abstraction should have no impact on clients; that is, their code should not have to be recompiled.
  • You want to hide the implementation of an abstraction completely from clients.
  • You have a proliferation of classes as shown earlier in the first Motivation diagram. Such a class hierarchy indicates the need for splitting an object into two parts. Rumbaugh uses the term “nested generalizations” to refer to such class hierarchies.
  • You want to share an implementation among multiple objects(perhaps using reference counting), and this fact should be hidden from the client.

Composite Method Design Patterns

Composite Method or Composite Design Patterns it compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

When to use Composite Method

  • You want to represent part-whole hierarchies of objects.
  • You want clients to be able to ignore the difference between compositions of objects and individual objects.Clients will treat all objectsin the composite structure uniformly.

Decorator Method Design Patterns

Decorator Method or Decorator Design Patterns also known as wrapper, it is attach with additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

When to use Decorator Method

  • To add responsibilities to individual objects dynamically and transparently, that is, without affecting other objects.
  • For responsibilities that can be withdrawn.
  • When extension by subclassing is impractical. Sometimes a large number of independent extensions are possible and would produce an explosion of subclasses to support every combination. Or a class definition maybe hidden or otherwise unavailable for subclassing.

Facade Method Design Patterns

Facade method or Facade Design Pattern it provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.

When to use Facade Method

  • You want to provide a simple interface to a complex subsystem. Subsystems often get more complex as they evolve. Most patterns, when applied, result in more and smaller classes. This makes the subsystem more reusable and easier to customize, but it also becomes harder to use for clients that don’t need to customize it. A facade can provide a simple default view of the subsystem that is good enough for most clients. Only clients needing more customizability will need to look beyond the facade.
  • There are many dependencies between clients and theimplementation classes of an abstraction.Introduce a facade to decouple the subsystem from clients and other subsystems, thereby promoting subsystem independence and portability.
  • You want to layer your subsystems. Use a facade to define an entry point to each subsystem level. If subsystems are dependent, then you can simplify the dependencies between them by making them communicate with each other solely through their facades.

Flyweight Method Design Patterns

Flyweight method or Flyweight Design Patterns, it is used to support large numbers of fine-grained objects efficiently.

When to use Flyweight Method

  • The Flyweight pattern’s effectiveness depends heavily on how and where it’s used. Apply the Flyweight pattern when allof the following are:
  • An application uses a large number of objects.
  • Storage costs are high because ofthe sheer quantity of objects.
  • Most object state canbe made extrinsic.
  • Many groups of objects may be replaced by relatively few shared objects once extrinsic state is removed.
  • The application doesn’t depend on object identity. Since flyweight objects may be shared, identity tests will return true for conceptually distinct objects.

Proxy Method Design Patterns

Proxy Method or Proxy Design Pattern also known as Surrogate, it provide a surrogate or placeholder for another object to control access to it.

When to use Proxy Method

Proxy method is applicable whenever there is a need for a more versatile or sophisticated reference to an object than a simple pointer. Here are several common situations in which the Proxy pattern is applicable:

  • A remote proxy provides a local representative for an object in a different address space.
  • A virtual proxy creates expensive objects on demand.
  • A protection proxy controls access to the original object. Protection proxies are useful when objects should have different access rights
  • A smart reference is a replacement for a bare pointer that performs additional actions when an object is accessed.


Previous Article
Next Article

Similar Reads

Difference Between Architectural Style, Architectural Patterns and Design Patterns
Many software professionals think that architectural styles and patterns are the same. Sadly, some of the software developers don’t understand the difference between architectural patterns and design patterns. In this article, we're going to summarize the differences between them. According to MSDN, architectural styles and patterns are the same th
7 min read
Connectivity and Composition Patterns | Design Patterns for Cloud Native Applications
In cloud-native applications, the architectural design becomes a critical aspect, defining the success of the entire solution. Connectivity and composition patterns are fundamental design principles that dictate how different components within a cloud-native application communicate and collaborate. Let's delve deeper into the significance of these
9 min read
Difference between Structural Diagrams and Behavioral Diagrams
Structural and behavioral diagrams are two types of diagrams used in UML (Unified Modeling Language) to represent different aspects of a system. While both types of diagrams are used to model different aspects of a system, they serve different purposes and focus on different aspects of the system. What are Structural Diagrams?Structural diagrams in
2 min read
Structural Diagrams | Unified Modeling Language(UML)
Complex applications need collaboration and planning from multiple teams and hence require a clear and concise way to communicate amongst them. So UML becomes essential to communicate with non-programmers about essential requirements, functionalities, and processes of the system. UML is linked with object-oriented design and analysis. UML makes use
6 min read
Composite Design Pattern | JavaScript Design Patterns
The Composite Design pattern is a way of organizing objects. It helps us handle different objects in a similar way when they are put together to create a structure with parts and wholes. These parts and wholes are like building blocks that can be split into smaller pieces and then put together to make a tree-like structure. The composite design pat
6 min read
Strategy Method Design Pattern | C++ Design Patterns
Strategy Pattern is a behavioral design pattern that defines a family of interchangeable algorithms and allows them to be used interchangeably within a context. This pattern enables the algorithm to be selected at runtime, providing flexibility and promoting code reusability. Important Topics for the Strategy Method in C++ Design Patterns Example o
4 min read
Memento Design Pattern | C++ Design Patterns
Memento Design Pattern is a behavioral design pattern that provides a mechanism for capturing an object's internal state and restoring it to that state at a later time. This pattern is useful when we need to implement features like undo/redo functionality or when we want to save and restore an object's state for various reasons. Important Topics fo
7 min read
What is the Correlation Between System Design and Design Patterns?
System design and design patterns are closely related concepts in software engineering, with design patterns serving as reusable solutions to common design problems encountered during system design. System design and design patterns are interrelated concepts that work together to create robust and well-structured software systems. Important Topics
11 min read
Design Patterns Cheat Sheet - When to Use Which Design Pattern?
In system design, selecting the right design pattern is related to choosing the right tool for the job. It's essential for crafting scalable, maintainable, and efficient systems. Yet, among a lot of options, the decision can be difficult. This Design Patterns Cheat Sheet serves as a guide, helping you on the path toward optimal design pattern selec
7 min read
State Method Design Pattern | C++ Design Patterns
In software design, managing the behavior of an object according to its internal state is a common issue. The state pattern addresses this issue by allowing an object to alter its behavior every time its internal state changes. This pattern encapsulates each state in a separate class, which makes it easier to add new states and modify existing stat
7 min read
Article Tags :