Skip to content

Instantly share code, notes, and snippets.

@simonwoo
Last active March 28, 2016 12:27
Show Gist options
  • Select an option

  • Save simonwoo/493922779738ef39550e to your computer and use it in GitHub Desktop.

Select an option

Save simonwoo/493922779738ef39550e to your computer and use it in GitHub Desktop.

Adapter

The Adapter pattern allows otherwise incompatible classes to work together by converting the interface of one class into an interface expected by the clients.

Example:

Socket wrenches provide an example of the Adapter. A socket attaches to a ratchet, provided that the size of the drive is the same. Typical drive sizes in the United States are 1/2" and 1/4". Obviously, a 1/2" drive ratchet will not fit into a 1/4" drive socket unless an adapter is used. A 1/2" to 1/4" adapter has a 1/2" female connection to fit on the 1/2" drive ratchet, and a 1/4" male connection to fit in the 1/4" drive socket.

example

Facade

The Facade defines a unified, higher level interface to a subsystem that makes it easier to use.

Example:

Consumers encounter a Facade when ordering from a catalog. The consumer calls one number and speaks with a customer service representative. The customer service representative acts as a Facade, providing an interface to the order fulfillment department, the billing department, and the shipping department.

example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment