Skip to main content

Posts

Showing posts from December, 2014

Adapter Pattern

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: 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  Let say you want to use this existing method zipFile() i...