Null Object Pattern - Criticism

Criticism

This pattern should be used carefully as it can make errors/bugs appear as normal program execution.

Care should be taken not to implement this pattern just to void null checks and make code more readable, since the harder to read code may just move to another place and be less standard - such as when different logic must execute in case the object provided is indeed the Null Object. For the common pattern in most languages with reference types is to compare a reference to a single value referred to as null or nil. Also, there is additional need for testing that no code anywhere ever assigns null instead of the Null Object, because in most cases and languages with static typing, this is not a compiler error if the Null Object is of a reference type, although it would certainly lead to errors at run time in parts of the code where the pattern was used to avoid null checks. On top of that, in most languages and assuming there can be many Null Objects (i.e. the Null Object is a reference type but doesn't implement the Singleton pattern in one or another way), checking for the Null Object instead of for the null or nil value introduces overhead, as does the singleton pattern likely itself upon obtaining the singleton reference.

Read more about this topic:  Null Object Pattern

Famous quotes containing the word criticism:

    It is ... pathetic to observe the complete lack of imagination on the part of certain employers and men and women of the upper-income levels, equally devoid of experience, equally glib with their criticism ... directed against workers, labor leaders, and other villains and personal devils who are the objects of their dart-throwing. Who doesn’t know the wealthy woman who fulminates against the “idle” workers who just won’t get out and hunt jobs?
    Mary Barnett Gilson (1877–?)

    Of all the cants which are canted in this canting world—though the cant of hypocrites may be the worst—the cant of criticism is the most tormenting!
    Laurence Sterne (1713–1768)

    A friend of mine spoke of books that are dedicated like this: “To my wife, by whose helpful criticism ...” and so on. He said the dedication should really read: “To my wife. If it had not been for her continual criticism and persistent nagging doubt as to my ability, this book would have appeared in Harper’s instead of The Hardware Age.”
    Brenda Ueland (1891–1985)