Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. interface IAnimal {
  2.     void Bark();
  3.     void Eat(Food food);
  4. }
  5.  
  6. interface IBrainy {
  7.     void Act();
  8. }
  9.  
  10. class Dog : IAnimal Animal, IBrainy Brain {
  11.     void as Animal.Bark(), Brain.Act {
  12.         // Bark
  13.     }
  14.    
  15.     void as Animal.Eat(Food food) {
  16.         // Eat
  17.     }
  18. }
  19.  
  20. // Example of inheriting classes
  21. class TalkingDog : Dog Dog, IBrainy TalkingBrain {
  22.     void as TalkingBrain.Act() {
  23.         // Talk
  24.     }
  25. }
  26.  
  27. /**** Invocation example ****/
  28. var dog = new Dog();
  29. dog.Act(); // obvious single implementation
  30. var talkingDog = new TalkingDog();
  31. talkingDog[TalkingBrain].Act(); // call the TalkingBrain implementation
  32. // Getting a specific implementation is recursive, as via multi inheritance you can implement a method twice in both parent classes, thus requiring double implementation specification
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement