Java Reference
In-Depth Information
Chapter 2. Behavioral Patterns
Introduction to Behavioral Patterns
Behavioral patterns are concerned with the flow of control through a system. Some ways of organizing control
within a system can yield great benefits in both efficiency and maintainability of that system. Behavioral patterns
distill the essence of proven practices into readily understood, well known, and easy-to-apply heuristics.
Behavioral patterns covered in this chapter are as follows:
Chain of Responsibility - To establish a chain within a system, so that a message can either be handled at the
level where it is first received, or be directed to an object that can handle it.
Command - To wrap a command in an object so that it can be stored, passed into methods, and returned like any
other object.
Interpreter - To define an interpreter for a language.
Iterator - To provide a consistent way to sequentially access items in a collection that is independent of and
separate from the underlying collection.
Mediator - To simplify communication among objects in a system by introducing a single object that manages
message distribution among the others.
Memento - To preserve a “snapshot” of an object's state, so that the object can return to its original state
without having to reveal its content to the rest of the world.
Observer - To provide a way for a component to flexibly broadcast messages to interested receivers.
State - To easily change an object's behavior at runtime.
Strategy - To define a group of classes that represent a set of possible behaviors. These behaviors can then be
flexibly plugged into an application, changing the functionality on the fly.
Visitor - To provide a maintainable, easy way to perform actions for a family of classes. Visitor centralizes the
behaviors and allows them to be modified or extended without changing the classes they operate on.
Template Method - To provide a method that allows subclasses to override parts of the method without
rewriting it.
Note:
MVC, or Model-View-Controller, can be considered a behavioral pattern. However, because of its wide-ranging
implications for entire systems, particular in view of the J2EE specification recommendations for servlets and
JSPs, we included it in the “ System Patterns ” chapter on page 208.
 
 
Search WWH ::




Custom Search