NullObject

[PLoPD3]

Behavioral , Relationship

Intent

How can you represent a partial relationship?

Solution

  • Declare a “nothing” or default object class
    1. Null object shares interface with real object, thus they must share an ancestor class
    2. Relationship is with ancestor class
    3. Client class *always* has a relationship with another object (either the “real object” or the Null Object)
    4. Null Object may perform default operations

    Consequences

    Related Patterns

    Source: [PLoPD3]

    Null Object Pattern, Bobby Wolf, in

    Pattern Languages of Program Design 3

    Pattern Languages of Program Design 3  [Barnes&Noble]