The Façade

Intent

Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use. (GoF)

Example

When planning a vacation, business trip, or other travel there are a lot of different aspects that have to be reserved, scheduled, and otherwise arranged for. Each of these elements (a hotel, a rental car, etc.) has a different way of accessing it. In the past, this would involve lots of phone calls, the use of a legacy system called Saber, some faxes… A lot of people preferred to use a travel agent to handle all of these details. Continue reading “The Façade”

The Adapter

Intent

Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces. (GoF)

Example

Many of the patterns require a consistent interface while implementation is allowed to vary. The Strategy is a good example. If such a pattern is used then client objects are designed to that interface, allowing for additional implementations to be added in the future without changes to the clients (following open-closed). If a new implementation is provided, perhaps a purchased component or an implementing class provided by another team, then it may not fit into the existing pattern. An Adapter can be added to solve this problem. Continue reading “The Adapter”

The Strategy

Intent

Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it. (GoF)

Example

Businesses purchase various equipment, properties, vehicles and so forth as required to operate. The cost of these “assets” can be deducted from the profits of the business, reducing their tax liability. Continue reading “The Strategy”

The Abstract Factory

Intent

Create an interface for creating sets of dependent or related instances that implement a set of abstract types.

The Abstract Factory coordinates the instantiation of sets of objects that have varying implementations in such a way that only legitimate combinations of instances are ever created.

Example

If an application is to be deployed on a variety of operating systems, it will need the “right one” of a number of different drivers such as Memory access, keyboard, mouse, file system, display, and sound. The right set of drivers for Windows will be different from the set of drivers for Linux, and yet different from those for OSX. Under no circumstances should a Windows display driver be used alongside a Linux memory manager. And so forth. Drivers “go together.” They are a family. Continue reading “The Abstract Factory”