An Adapter as the name says is used to provide a mechanism that adapts an existing interface to the required interface. This helps the types that are not designed to work together, work together.
Adapter pattern may become handy when working with legacy system. Here adapter allows the use of interfaces that are incompatible with new interface requirement. For example, an object needs to compress a file. You find that there is another class that provide the compression service, but has a different method signature than the one required by the object. An adapter patter can come to rescue in such situations. We can create an adapter class that allows the existing service to be used through a new interface.
There are two kinds of adapters:
Bibliography
Adapter pattern may become handy when working with legacy system. Here adapter allows the use of interfaces that are incompatible with new interface requirement. For example, an object needs to compress a file. You find that there is another class that provide the compression service, but has a different method signature than the one required by the object. An adapter patter can come to rescue in such situations. We can create an adapter class that allows the existing service to be used through a new interface.
There are two kinds of adapters:
- Class Adapter - This type of adapters adapters through sub-classing
- Object Adapter - This type of adapter use delegation to adapt instead of subclassing
Class Adapter
Object Adapter
Bishop, J. (2016, 12 30). Structural Patterns: Adapter and Façade. Retrieved from MSDN:https://msdn.microsoft.com/en-us/library/orm-9780596527730-01-04.aspx
Comments
Post a Comment