DEV Community

Discussion on: Null Object Pattern

Collapse
 
pdeveloper profile image
PDeveloper

A better example would be in order, since the one presented doesn't make sense - what is the context of calling calculateSpeed without a specific car? For that function, it should specifically enforce that a parameter be passed.

If there is a place in your code where you are okay with using context-free default values, it usually means that it's unnecessary to call that code in the first place, and the real architectural issue lies higher up.

I can see this being useful in specific cases though, where you're dealing with undefined input, and the default object / values are logical to be useful further on.