Last active
January 13, 2026 21:36
-
-
Save sunmeat/a1f7fb5bb886fd1ccaf111c90663baf5 to your computer and use it in GitHub Desktop.
ISP nice example C#
This file contains hidden or 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
| interface IFlyable | |
| { | |
| void Fly(); | |
| } | |
| interface IEatable | |
| { | |
| void Eat(); | |
| } | |
| interface ITweetable | |
| { | |
| void Tweet(); | |
| } | |
| interface ISwimable | |
| { | |
| void Swim(); | |
| } | |
| class Sparrow : IFlyable, IEatable, ITweetable | |
| { | |
| // ... | |
| public void Fly() | |
| { | |
| Console.WriteLine("Горобець летить..."); | |
| } | |
| public void Tweet() | |
| { | |
| Console.WriteLine("Горобець цвірінькає..."); | |
| } | |
| public void Eat() | |
| { | |
| Console.WriteLine("Горобець їсть..."); | |
| } | |
| } | |
| class Duck : IFlyable, IEatable, ISwimable | |
| { | |
| // ... | |
| public void Fly() | |
| { | |
| Console.WriteLine("Качка летить..."); | |
| } | |
| public void Eat() | |
| { | |
| Console.WriteLine("Качка їсть..."); | |
| } | |
| public void Swim() | |
| { | |
| Console.WriteLine("Качка плаває..."); | |
| } | |
| } | |
| class Penguin : IEatable, ISwimable | |
| { | |
| // ... | |
| public void Swim() | |
| { | |
| Console.WriteLine("Пінгвін плаває..."); | |
| } | |
| public void Eat() | |
| { | |
| Console.WriteLine("Пінгвін їсть..."); | |
| } | |
| } | |
| class Program | |
| { | |
| static void Main() | |
| { | |
| Console.OutputEncoding = System.Text.Encoding.UTF8; | |
| var sparrow = new Sparrow(); | |
| sparrow.Fly(); | |
| sparrow.Tweet(); | |
| sparrow.Eat(); | |
| var duck = new Duck(); | |
| duck.Fly(); | |
| duck.Eat(); | |
| duck.Swim(); | |
| var penguin = new Penguin(); | |
| penguin.Eat(); | |
| penguin.Swim(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment