The need for nullable reference types to advertise optional constructor dependencies

In "traditional" OOP, you advertise your class required dependencies via constructor arguments:

public Foo(IOutput output, ILogger logger, ...)

Typically, the first few lines of code will check that these dependencies are not null.

Optional dependencies may be provided as properties, which you can leave unset (null).

Internally, in order to avoid a multitude of conditionals checking for nulls, you might have your own "null" implementations of the dependencies' interfaces (i.e. NullLogger which does nothing). This way the code is more readable, and you can always assume the dependencies are non-null and you'll never get a NullReferenceException ;)...

Read full article

Published 18 July 2008 07:42 AM by Daniel Cazzulino
Filed under: ,

Comments

No Comments

Search

Go

This Blog

News

     

      Microsoft MVP Profile

Syndication