code_junkie

Interface vs Base class

Nov 10th, 2011
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. public abstract class Mammal
  2.  
  3. public class Dog : Mammal
  4. public class Cat : Mammal
  5.  
  6. public class Giraffe : Mammal
  7. public class Rhinoceros : Mammal
  8. public class Hippopotamus : Mammal
  9.  
  10. public interface IPettable
  11. {
  12. IList<Trick> Tricks{get; set;}
  13. void Bathe();
  14. void Train(Trick t);
  15. }
  16.  
  17. public class Dog : Mammal, IPettable
  18. public class Cat : Mammal, IPettable
  19.  
  20. public class Pet
  21. {
  22. void Bathe();
  23. void Train(Trick t);
  24. }
  25.  
  26. public class Dog
  27. {
  28. private Pet pet;
  29.  
  30. public void Bathe() { pet.Bathe(); }
  31. public void Train(Trick t) { pet.Train(t); }
  32. }
  33.  
  34. public class Cat
  35. {
  36. private Pet pet;
  37.  
  38. public void Bathe() { pet.Bathe(); }
  39. public void Train(Trick t) { pet.Train(t); }
  40. }
Add Comment
Please, Sign In to add comment