Special Case

The Special Case pattern describes how to have your system seamlessly provide alternative, special-case behavior. It's a variant and refinement of the pattern Null Object, for which many authors have written many variants; it's also a refinement of the Strategy pattern from Design Patterns: Elements of Reusable Object-Oriented Software, by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides (Addison-Wesley Professional).

When you're designing with objects, you define the classes and objects to handle some responsibility or data. Sometimes, though, you need to remember that there isn't anything to save or to do, which is a special case of the data and responsibilities. Figure 23-1 shows a simple class diagram of Special Case.

The Special Case pattern is from Patterns of Enterprise Application Architecture, by Martin Fowler (Addison-Wesley).

images

Figure 23-1: The classes of Special Case.

Get Pattern-Oriented Software Architecture For Dummies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.