Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace DepthFix
  9. {
  10. class Program
  11. {
  12.  
  13. interface FlyAble
  14. {
  15. void Fly();
  16. }
  17.  
  18.  
  19. abstract class Animal
  20. {
  21. public void Describe()
  22. {
  23. Console.WriteLine("This animal is a: " + GetName() + " it makes following sound: " + GetNoise() + " and eats: " + GetFood() + " and drinks: " + GetLiquid());
  24.  
  25. var flyAble = this as FlyAble;
  26.  
  27. if (flyAble != null)
  28. flyAble.Fly();
  29. }
  30.  
  31. protected abstract string GetName();
  32.  
  33. protected abstract string GetNoise();
  34.  
  35. protected abstract string GetFood();
  36.  
  37. protected virtual string GetLiquid()
  38. {
  39. return "Wasser";
  40. }
  41.  
  42. }
  43.  
  44.  
  45. class Duck : Animal
  46. {
  47. protected override string GetName()
  48. {
  49. return "Ente";
  50. }
  51.  
  52. protected override string GetNoise()
  53. {
  54. return "Quack";
  55. }
  56.  
  57. protected override string GetFood()
  58. {
  59. return "10 Körner";
  60. }
  61. }
  62.  
  63. class SuperDuck : Duck, FlyAble
  64. {
  65. protected override string GetName()
  66. {
  67. return "SuperEnte";
  68. }
  69.  
  70. protected override string GetFood()
  71. {
  72. return base.GetFood() + " und 1 Sack Reis";
  73. }
  74.  
  75. protected override string GetLiquid()
  76. {
  77. return "5 Flaschen Rum";
  78. }
  79.  
  80. public void Fly()
  81. {
  82. Console.Error.WriteLine("Turboflug");
  83. }
  84. }
  85.  
  86. static void Main(string[] args)
  87. {
  88. IList<Animal> tiere = new List<Animal>();
  89.  
  90. tiere.Add(new Duck());
  91. tiere.Add(new SuperDuck());
  92.  
  93. foreach (var tier in tiere)
  94. tier.Describe();
  95.  
  96.  
  97. Console.ReadLine();
  98. }
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement