Skip to content

Instantly share code, notes, and snippets.

@smudge202
Created June 17, 2015 11:38
Show Gist options
  • Save smudge202/b8f6e2d6a7a6f99823c8 to your computer and use it in GitHub Desktop.
Save smudge202/b8f6e2d6a7a6f99823c8 to your computer and use it in GitHub Desktop.
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