Created
September 30, 2020 00:40
-
-
Save MelbourneDeveloper/8d6289d249cce4b3c7a8135d68c054ab to your computer and use it in GitHub Desktop.
Inheritance with null objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class BaseClass | |
{ | |
protected ILogger Logger { get; } | |
protected BaseClass(ILogger logger) | |
{ | |
Logger = logger; | |
} | |
} | |
public class ConcreteClass : BaseClass | |
{ | |
readonly ILoggerFactory _loggerFactory; | |
public ConcreteClass(ILoggerFactory loggerFactory) | |
: base((loggerFactory ?? NullLoggerFactory.Instance).CreateLogger<ConcreteClass>()) | |
{ | |
_loggerFactory = loggerFactory ?? NullLoggerFactory.Instance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment