Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace DepthFix
- {
- class Program
- {
- interface FlyAble
- {
- void Fly();
- }
- abstract class Animal
- {
- public void Describe()
- {
- Console.WriteLine("This animal is a: " + GetName() + " it makes following sound: " + GetNoise() + " and eats: " + GetFood() + " and drinks: " + GetLiquid());
- var flyAble = this as FlyAble;
- if (flyAble != null)
- flyAble.Fly();
- }
- protected abstract string GetName();
- protected abstract string GetNoise();
- protected abstract string GetFood();
- protected virtual string GetLiquid()
- {
- return "Wasser";
- }
- }
- class Duck : Animal
- {
- protected override string GetName()
- {
- return "Ente";
- }
- protected override string GetNoise()
- {
- return "Quack";
- }
- protected override string GetFood()
- {
- return "10 Körner";
- }
- }
- class SuperDuck : Duck, FlyAble
- {
- protected override string GetName()
- {
- return "SuperEnte";
- }
- protected override string GetFood()
- {
- return base.GetFood() + " und 1 Sack Reis";
- }
- protected override string GetLiquid()
- {
- return "5 Flaschen Rum";
- }
- public void Fly()
- {
- Console.Error.WriteLine("Turboflug");
- }
- }
- static void Main(string[] args)
- {
- IList<Animal> tiere = new List<Animal>();
- tiere.Add(new Duck());
- tiere.Add(new SuperDuck());
- foreach (var tier in tiere)
- tier.Describe();
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement