CS 4773 Object Oriented Systems Introduction to Design Patterns


Skim through the first 5 chapters of the Design Patterns Book.
Read Chapters 6 and 7

Introduction


The Facade Pattern

Original short description:
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.

The facade pattern gives a simplified interface that hides the complexity of the underlying system.

Example 1:
A client needs to make certain restrictive queries to a database.
The client does not need to know about the details of how to make general database queries.

Example 2:
A client needs to be able to ask a question and return a yes or no answer from an interactive user.

Solution:

First implementation:
How well does this do?
What are the public methods of QuestionAsker?

Second implementation:

Third implementation:


The Adapter Pattern

Original short description:
Convert the interface of a class into another interface that the clients expect.
Adapter lets classes work together that could not otherwise because of incompatible interfaces.

The Adapter pattern is used when the client's interface is already determined but does not match the existing interface needed class.

Example: Before Java existed there was an animation package called XTango.


Comparison of Facade and Adapter Patterns

FacadeAdapter
Provides a wrapper for existing classes Provides a wrapper for existing classes
No predefined interface for the client A predefined interface for the client exists
Simplifies the interface to existing classes Changes the interface to existing classes
Hides the interface of the existing classes Not required to hide the existing interface
Not interested in polymorphic behavior May be interested in polymorphic behavior
Often hides some functionality of existing classes Usually does not hide functionality of existing classes