Introducing behavioral design patterns
In Chapter 1, Unified Modeling Language Primer, we learned that behavioral diagrams illustrate how system components interact to form a system. We examined the following behavioral diagrams—activity diagram, interaction diagram, state Machine diagram, and use case diagram. It follows that behavioral design patterns are focused on the interaction of objects and classes in a system. The key component here is the interaction, also referred to as the communication between objects and classes.
The twelve behavioral design patterns presented in this chapter can be grouped into two subcategories—those that focus on classes and those that focus on objects. The following table details the subcategories:
The behavioral design patterns listed in the preceding table are detailed in the remaining sections of this chapter. They are presented in alphabetical order to illustrate that one is not more important than the others. Here is a brief description of each design pattern's applicability to the behavioral design category. These are further detailed in subsequent sections of this chapter:
- Chain of responsibility pattern: An object submits a request to multiple objects without knowing which object will handle the request
- Command pattern: Permits the sending of requests without knowing details about the receiver or even about what is being requested
- Interpreter pattern: Used to establish a grammatical representation and an interpreter that interprets language
- Iterator pattern: Grants access to an object's members without sharing the encapsulated data structures
- Mediator pattern: Used to permit object interactions without using explicit object references
- Memento pattern: Saves an object's current internal state as a memento so that it can be referred to and restored to
- Null object pattern: Negates the need to search for the null condition
- Observer pattern: Updates subscriber objects when a change is made to the publisher object's state
- State pattern: Allows an object to change its behavior based on internal state changes
- Strategy pattern: Allows us to individually encapsulate a set of interchangeable algorithms
- Template method pattern: Involves creating an algorithm template with processing steps relegated to child classes
- Visitor pattern: Performs operations on an object without altering its structure