Why Fowler PoEAA p. 498 define the null object pattern as follows (sample abbreviated, C # language, but not relevant):
public class Customer { public virtual string Name {get; set;} } public class NullCustomer : Customer, INull { public override Name { get { return "ImTheNull";}
INull used as a marker interface. I do not like this approach for three reasons:
- Properties must be marked as virtual.
- I can no longer close entity classes
- At least (n + 1) new types are introduced (n null objects, one marker interface)
Why is this not implemented like this:
public class Customer { public static readonly Customer NullCustomer = new Customer(){Name = "ImtTheNullCustomer";} public string Name {get; set;} }
As a rule, I found all the Fowler examples well thought out, and there should obviously be something that I missed here.
source share