Why does Fowler PoEAA p. 498 define the null-object pattern in the following way (sample shortened, language is c# but doesn't matter):
public class Customer
{
public virtual string Name {get; set;}
}
public class NullCustomer : Customer, INull
{
public override Name
{
get { return "ImTheNull";}
// setter ommitted
}
}
INull
is used as a marker interface.
I don't really like this approach for three reasons:
- Properties need to be marked virtual
- I can't seal my entity classes anymore
- At least (n+1) new types are introduced (n null objects, one marker interface)
Why isn't it implemented like this:
public class Customer
{
public static readonly Customer NullCustomer = new Customer(){Name = "ImtTheNullCustomer";}
public string Name {get; set;}
}
I have generally found all of Fowlers examples well thought and there clearly must be something I have missed here.