A ratchet wrench uses a suite of sockets. The large sockets require a 3/8" square fitting, and the small sockets require a 1/4" fitting. The wrench itself only supplies the 3/8" fitting. But – a 3/8" to 1/4" adapter readily bridges the mismatch.

The Adapter pattern allows otherwise incompatible classes to work together by converting the interface of one class into an interface expected by the other class. [Michael Duell, "Non-software examples of software design patterns"]

   

    Pictures often have frames added, and it is the frame which is actually hung on the wall. One or more mats are also optional. When complete, the painting, the mat(s), and the frame form a single visual component.

The Decorator pattern demonstrates how to support many permutations of core and optional features in software – all the features are mapped to classes that each implement a common interface, and then the user can mix and match any set of features she desires. [Michael Duell, "Non-software examples of software design patterns"]

The Mediator defines an object that controls how a set of objects interact. Loose coupling between colleague objects is achieved by having colleagues communicate with the Mediator, rather than with each other. The control tower at a controlled airport demonstrates this pattern very well. The pilots of the planes approaching or departing the terminal area communicate with the tower rather than explicitly communicating with one another. The constraints on who can take off or land are enforced by the tower. It is important to note that the tower does not control the whole flight. It exists only to enforce constraints in the terminal area. [Michael Duell, "Non-software examples of software design patterns", Object Magazine, Jul 97, p54]    

    The Observer defines a one-to-many relationship so that when one object changes state, the others are notified and updated automatically. Some auctions demonstrate this pattern. Each bidder possesses a numbered paddle that is used to indicate a bid. The auctioneer starts the bidding, and "observes" when a paddle is raised to accept the bid. The acceptance of the bid changes the bid price which is broadcast to all of the bidders in the form of a new bid. [Michael Duell, "Non-software examples of software design patterns", Object Magazine, Jul 97, p54]

The Proxy provides a surrogate or place holder to provide access to an object. A check or bank draft is a proxy for funds in an account. A check can be used in place of cash for making purchases and ultimately controls access to cash in the issuer's account. [Michael Duell, "Non-software examples of software design patterns", Object Magazine, Jul 97, p54]    

    The Chain of Responsibility pattern avoids coupling the sender of a request to the receiver by giving more than one object a chance to handle the request. Mechanical coin sorting banks use the Chain of Responsibility. Rather than having a separate slot for each coin denomination coupled with a receptacle for the denomination, a single slot is used. When the coin is dropped, the coin is routed to the appropriate receptacle by the mechanical mechanisms within the bank. [Michael Duell, "Non-software examples of software design patterns", Object Magazine, Jul 97, p54]

From Head First Design Patterns ... A coffee shop has 4 kinds of coffee: HouseBlend, DarkRoast, Expresso, Decaf; and 4 optional condiments: Milk, Mocha, Soy, Whip. Defining a class for all interesting combinations results in an explosion of classes.

The Decorator pattern suggests:
  1. Create a "Lowest Common Denominator" interface that makes all classes interchangeable.
  2. Create a second level base class (CondimentDecorator) to support the optional wrapper classes.
  3. The coffee classes and Decorator class inherit from the LCD interface.
  4. The Decorator class declares a "has a" relationship to the LCD interface, and this data member is initialized in its constructor.
  5. The Decorator class delegates to the LCD object.
  6. Define a Decorator derived class for each optional condiment.
  7. Decorator derived classes implement their wrapper functionality - and - delegate to the Decorator base class.
  8. The client configures the type and order of coffee and condiment objects.

    Beverage drink = new Whip( new Mocha( new DarkRoast() ) );
    print( "The total cost is " + drink.cost() );

  1. Whip's cost() method calls cost() on its inner "component" (a Mocha object)
  2. Mocha's cost() method calls cost() on its inner "component" (a DarkRoast object)
  3. DarkRoast's cost() method returns $2.20
  4. Mocha's cost() method adds its $0.60 to the $2.20 and returns $2.80
  5. Whip's cost() method adds its $0.40 to the $2.80 and returns $3.20