I have been reading about design patterns and this got me curious:
Decorator Pattern says wrap an original object and add additional features in the wrapper object. So structurally speaking - Wrappers follow decorator pattern.
Adapter pattern says changing one object by creating an instance of it and adding functionalities to it. These functionalities do not match those of the original object so we have to modify them, but we may also add our own extra methods which are not a part of the original object.
In this regard, what is the difference between Adapter and Decorator design pattern?
Adapter changes the interface of an existing object, while Decorator enhances an object without changing its interface.
The main differences between Adapter and Proxy patterns are:While proxy provides the same interface, Adapter provides a different interface that's compatible with its client. Adapter pattern is used after the application components are designed so that we can use them without modifying the source code.
Disadvantages. High degree of flexibility. High complexity of software (especially decorator interface) Expansion of function of classes without inheritance.
Adapter uses composition to forward calls from target interface to adaptee interface, Decorator also uses same technique before adding new behavior, Facade is composed of all sub components and Proxy also use composition and delegation to forward requests.
Decorator, attach additional responsibilities to an object dynamically. For example adding sugar in a coffee.
Adapter, adapts interface of an existing class to another interface. For example eletrical adapter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With