Non-null objects, the Null Object pattern, and T.init

Adam D. Ruppe destructionator at gmail.com
Fri Jan 17 06:13:39 PST 2014


On Friday, 17 January 2014 at 14:06:59 UTC, Ola Fosheim Grøstad 
wrote:
> Like if you delete a User object, then all "weak" pointers are 
> set to a UnknownUser default object. So that you can call 
> user.isLoggedIn() and get false, but you should be able to 
> default to a different Class to get a different set of virtual 
> calls.

This particular thing is easy enough to do with null too:

bool isLoggedIn(User user) {
     return user is null ? false : user.isLoggedInImpl();
}



More information about the Digitalmars-d mailing list