Structural Design Pattern
- Anand Nerurkar
- May 2, 2024
- 2 min read
Structural Design Pattern
==
Adapter Patterm
An Adapter Pattern says that just "converts the interface of a class into another interface that a client wants".
In other words, to provide the interface according to client requirement while using the services of a class with a different interface.
The Adapter Pattern is also known as Wrapper.
It allows
two or more previously incompatible objects to interact.
reusability of existing functionality.
UML for Adapter Pattern:
There are the following specifications for the adapter pattern:
Target Interface: This is the desired interface class which will be used by the clients.
Adapter class: This class is a wrapper class which implements the desired target interface and modifies the specific request available from the Adaptee class.
Adaptee class: This is the class which is used by the Adapter class to reuse the existing functionality and modify them for desired use.
Client: This class will interact with the Adapter class.
Proxy Pattern
Simply, proxy means an object representing another object.
According to GoF, a Proxy Pattern "provides the control for accessing the original object".
So, we can perform many operations like hiding the information of original object, on demand loading etc.
Proxy pattern is also known as Surrogate or Placeholder.
provides the protection to the original object from the outside world.
Flywaight pattern
Composite pattern
Facade pattern
A Facade Pattern says that just "just provide a unified and simplified interface to a set of interfaces in a subsystem, therefore it hides the complexities of the subsystem from the client".
In other words, Facade Pattern describes a higher-level interface that makes the sub-system easier to use.
Practically, every Abstract Factory is a type of Facade.
Bridge pattern
A Bridge Pattern says that just "decouple the functional abstraction from the implementation so that the two can vary independently".
The Bridge Pattern is also known as Handle or Body.
It enables
the separation of implementation from the interface.
improves the extensibility
hiding of implementation details from the client.
The bridge pattern can be demonstrated with an example. Suppose we have a Vehicle class. We can extract out the implementation of the engine into an Engine class. We can reference this Engine implementor in our Vehicle via an Engine field. We'll declare Vehicle to be an abstract class. Subclasses of Vehicle need to implement the drive() method. Notice that the Engine reference can be changed via the setEngine() method.
Decorator pattern
A Decorator Pattern says that just "attach a flexible additional responsibilities to an object dynamically".
In other words, The Decorator Pattern uses composition instead of inheritance to extend the functionality of an object at runtime.
The Decorator Pattern is also known as Wrapper.
Comments