Skip to content

Instantly share code, notes, and snippets.

@sunmeat
Last active January 13, 2026 21:36
Show Gist options
  • Select an option

  • Save sunmeat/a1f7fb5bb886fd1ccaf111c90663baf5 to your computer and use it in GitHub Desktop.

Select an option

Save sunmeat/a1f7fb5bb886fd1ccaf111c90663baf5 to your computer and use it in GitHub Desktop.
ISP nice example C#
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