Created
June 17, 2015 11:38
-
-
Save smudge202/b8f6e2d6a7a6f99823c8 to your computer and use it in GitHub Desktop.
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 interface IAnimal | |
{ | |
string Type { get; } | |
} | |
public interface IDog : IAnimal { } | |
public class Foo | |
{ | |
public Foo(IDog animal) | |
{ | |
Console.WriteLine($"Type: {animal.Type}"); | |
// a new requirement arrives, the dog now has to Bark | |
// the fix is *NOT* to change existing code | |
// Ref: Open/Close Principle | |
} | |
} | |
// instead: | |
public interface IBark : IDog | |
{ | |
void Bark(); | |
} | |
public class Bar : Foo | |
{ | |
public Bar(IBark bark) : base(bark) | |
{ | |
bark.Bark(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment