static void Main(string[] args) { var meineSchwimmers = new ISwimable[] { new Ente(), new Fisch() }; foreach (var schwimmer in meineSchwimmers) { schwimmer.Schwimmen(); } Console.ReadLine(); }
static void Main() { List <Animal> animals = new List <Animal> { new Person("Person", 20), new Dog(5, 20) }; foreach (Animal animal in animals) { animal.Talk(); animal.TakeBreath(); } List <IJumpable> jumpables = new List <IJumpable> { new Person("Person", 20), new Dog(5, 20) }; foreach (IJumpable jumpable in jumpables) { jumpable.Jump(10); } List <IMoveable> moveables = new List <IMoveable> { new Person("Person", 20), new Dog(5, 20) }; foreach (IMoveable moveable in moveables) { moveable.Move(); } Person person = new Person("Person", 30); ISwimable swimable = person; swimable.Move(); IMoveable moveable1 = person; moveable1.Move(); }
static void Main(string[] args) { Duck duck = new Duck(); Penguin penguin = new Penguin(); Dolphin dolphin = new Dolphin(); duck.Move(); duck.Eat(); penguin.Move(); penguin.Eat(); dolphin.Move(); dolphin.Eat(); IFlyable duck2 = duck as IFlyable; duck2.Fly(); IWalkable penguin2 = penguin as IWalkable; penguin2.Walk(); ISwimable dolphin2 = dolphin as ISwimable; dolphin2.Swim(); string direction = Direction.down.ToString(); duck.Move(direction); direction = Direction.up.ToString(); penguin.Move(direction); Console.ReadKey(); }
protected Bird() { _flyable = new NoFlyable(this.GetType().Name); _swimable = new NoSwimable(this.GetType().Name); }
public void SetSwimBehavior(ISwimable swimable) { _swimable = swimable; }
static void Main(string[] args) { VehicleFactory vf = new VehicleFactory(); CVehicle[] vehicle = new CVehicle[10]; for (int i = 0; i < vehicle.Length; i++) { vehicle[i] = vf.NextVehicle(); } for (int i = 0; i < vehicle.Length; i++) { vehicle[i].Print(); } CVehicle maxPrice = null; int countCars = 0; int countPlanes = 0; int countShips = 0; CCar[] masCars = new CCar[10]; CPlane[] masPlanes = new CPlane[10]; CShip[] masShips = new CShip[10]; int countVeh = 0; CVehicle[] masVeh = new CVehicle[10]; for (int i = 0; i < vehicle.Length; i++) { if (vehicle[i].GetType().Name == "CCar") { masCars[countCars++] = (CCar)vehicle[i]; } else if (vehicle[i].GetType().Name == "CPlane") { masPlanes[countPlanes++] = (CPlane)vehicle[i]; } else if (vehicle[i].GetType().Name == "CShip") { masShips[countShips++] = (CShip)vehicle[i]; } if (vehicle[i].GetType().Name != "CPlane") { if (maxPrice == null) { maxPrice = vehicle[i]; } else if (maxPrice.Price < vehicle[i].Price) { maxPrice = vehicle[i]; } } if (vehicle[i].Year > 2000 && vehicle[i].Year < 2010) { if (vehicle[i].GetType().Name == "CCar") { if (vehicle[i].Year > 2003) { masVeh[countVeh++] = vehicle[i]; } } else if (vehicle[i].GetType().Name == "CPlane") { masVeh[countVeh++] = vehicle[i]; } else if (vehicle[i].GetType().Name == "CShip") { if (vehicle[i].Year < 2005) { masVeh[countVeh++] = vehicle[i]; } } } } Console.WriteLine("Cars " + countCars); Console.WriteLine("Planes " + countPlanes); Console.WriteLine("Ships " + countShips); if (maxPrice != null) { maxPrice.Print(); } Console.WriteLine("--------------------------"); Array.Resize(ref masVeh, countVeh); for (int i = 0; i < masVeh.Length; i++) { masVeh[i].Print(); } Console.WriteLine("--------------------------"); SwimableVehicle sv = new SwimableVehicle(); ISwimable[] masSwim = new ISwimable[10]; for (int i = 0; i < masSwim.Length; i++) { masSwim[i] = sv.NextVehicle(); } int iSwimable = 0; for (int i = 0; i < vehicle.Length; i++) { if (vehicle[i] is ISwimable) { masSwim[iSwimable++] = vehicle[i] as ISwimable; } } Array.Resize(ref masSwim, iSwimable); for (int i = 0; i < masSwim.Length; i++) { Console.WriteLine(masSwim); } }
protected Duck(IDisplayable displayable, ISwimable swimable) { this.displayable = displayable; this.swimable = swimable; }