Choosing Names for Null or Missing Objects

The Null Object template is a great tool for test-based development. If I need to make the behavior of the system more complex, I enter a null object to quickly return to green. In addition, often a null object is useful for preservation for old unit tests. More details and other uses of the null object template:

http://en.wikipedia.org/wiki/Null_Object_pattern

Now that I have several of them in the system, I begin to think about how to name them. As a rule, do you just put Null as the first word in the name or do you give each null object its own name?

Let me give an example for discussion. Say I only wore black turtlenecks, but now I want to change my wardrobe a bit. I will name my new type WardrobeChooser. To encapsulate the previous behavior, I could call my old object NullWardrobeChooser or BlackTurtleneckWardrobeChooser or even MissingWardrobeChooser (yikes!), Which may be bad). What name would you recommend?

I looked on the Internet, but I can not find any links about this.

+4
source share
1 answer

Personally, I prefer not to use naming strategies for null objects and name them according to their behavior.

If you need time to find a convenient name, I think that prefixes like Empty or Default better than Null , because it just says that a null object pattern is used and nothing else.

Some examples of names for Null Objects: NoDiscount , EmptyIterator , DefaultPaymentStrategy , etc.

+2
source

Source: https://habr.com/ru/post/1386833/


All Articles