GofPatterns GofPatterns

Behavioral Patterns  «Prev 

Common Behavioral Patterns

Other behavioral object patterns are concerned with encapsulating behavior in an object and delegating requests to it.
  1. The Strategy pattern encapsulates an algorithm in an object and makes it easy to specify and change the algorithm an object uses.
  2. The Command pattern encapsulates a request in an object so that it can be passed as a parameter, stored on a history list, or manipulated in other ways.
  3. The State pattern encapsulates the states of an object so that the object can change its behavior when its state object changes.
  4. Visitor encapsulates behavior that would otherwise be distributed across classes, and
  5. Iterator abstracts the way you access andtraverse objects in an aggregate.

Chain of Responsibility Pattern describes a system in which different objects each receive an opportunity to handle a request. The request propagates up the chain until some object handles it. The Java 1.0 event model was based on this design pattern.

Command Pattern wraps requests from one object to another within a class. This allows requests to be easily stored, queued, and undone.

Iterator Pattern describes an abstract means of passing through each of the elements in a collection, whether that collection is a set, a list, an array, a hash table, or some other data structure. It separates the enumeration of the collection from the way the collection is stored.

The Mediator Pattern is perhaps the most common and sueful behavioral pattern. The Mediator Pattern allows many different objects of the same or different classes that need to communicate with each other to each communicate only with a single, central mediator.

Observer Pattern allows an Observer object to notice and react to changes in an Observed object. Each observed object maintains a list of Observers and notifies each of them whenever its relevant state changes. The Java 1.1 event model is based on this design pattern.

Strategy Pattern allows different algorithms to be incorporated into different classes. The algorithms can then be changed dynamically at runtime and adjusted to fit the needs of a specific situation.

Visitor Pattern lets you define a new operation without changing the classes of the elements on which it operates.