Wrapper Classes

A couple of the developers involved in our hiring process seem to be obsessed with the different wrapper patterns. That got me thinking about the differences between the Decorator, Adapter, Facade and Proxy patterns.

Here is a quick summary that compares and contrasts these four patterns:
  • The Decorator wraps a single class, exposes the same interface and adds functionality to the wrapped class which is injected into the Decorator.
  • The Adapter wraps a single class and changes its interface while maintaining functionality. Usually this is done to make the class easier to use in the consuming system.
  • The Facade wraps multiple classes and provides a simplified interface for using them together.
  • The Proxy wraps a single class and is similar to the Decorator in implementation, though it does not extend the functionality of the class, but hides an implementation detail such as network transport or lazy loading. The consumer shouldn't know it has a proxy rather than the real object.
This isn't a lot of detail and includes no implementation examples, but it is enough to get you through our interview phone if you can talk about about each of those logically.


Popular posts from this blog

Architecture at different levels of abstraction

TFS to SVN Conversion with History