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:
“I am opposed to writing about the private lives of living authors and psychoanalyzing them while they are alive. Criticism is getting all mixed up with a combination of the Junior F.B.I.- men, discards from Freud and Jung and a sort of Columnist peep- hole and missing laundry list school.... Every young English professor sees gold in them dirty sheets now. Imagine what they can do with the soiled sheets of four legal beds by the same writer and you can see why their tongues are slavering.”
—Ernest Hemingway (18991961)
“Cubism had been an analysis of the object and an attempt to put it before us in its totality; both as analysis and as synthesis, it was a criticism of appearance. Surrealism transmuted the object, and suddenly a canvas became an apparition: a new figuration, a real transfiguration.”
—Octavio Paz (b. 1914)
“Homoeopathy is insignificant as an art of healing, but of great value as criticism on the hygeia or medical practice of the time.”
—Ralph Waldo Emerson (18031882)