Guest User

Untitled

a guest
Jul 15th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. interface IDrivingBehavior {
  2.     void Drive();
  3. }
  4.  
  5. interface ISailingBehavior {
  6.     void Sail();
  7. }
  8.  
  9. public class DrivingBehavior : ISailingBehavior {
  10.     public void Drive () {
  11.         // logic here
  12.     }
  13. }
  14.  
  15. public class SailingBehavior : ISailingBehavior {
  16.     public void Sail() {
  17.         // logic here
  18.     }
  19. }
  20.  
  21. public class AmphibiousVehicle {
  22.     private IDrivingBehavior drivingBehavior = new DrivingBehavior();
  23.     private ISailingBehavior sailingBehavior = new SailingBehavior ();
  24.  
  25.     void drive() {
  26.         this.drivingBehavior.Drive();
  27.     }
  28.     void sail() {
  29.         this.sailingBehavior.Sail();
  30.     }
  31. }
  32.    
  33. public class Car {
  34.     private IDrivingBehavior drivingBehavior = new DrivingBehavior();
  35.  
  36.     void drive() {
  37.         this.drivingBehavior.Drive();
  38.     }
  39. }
  40.    
  41. public class Boat {
  42.     private ISailingBehavior sailingBehavior = new SailingBehavior ();
  43.  
  44.     void sail() {
  45.         this.sailingBehavior.Sail();
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment