Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface IDrivingBehavior {
- void Drive();
- }
- interface ISailingBehavior {
- void Sail();
- }
- public class DrivingBehavior : ISailingBehavior {
- public void Drive () {
- // logic here
- }
- }
- public class SailingBehavior : ISailingBehavior {
- public void Sail() {
- // logic here
- }
- }
- public class AmphibiousVehicle {
- private IDrivingBehavior drivingBehavior = new DrivingBehavior();
- private ISailingBehavior sailingBehavior = new SailingBehavior ();
- void drive() {
- this.drivingBehavior.Drive();
- }
- void sail() {
- this.sailingBehavior.Sail();
- }
- }
- public class Car {
- private IDrivingBehavior drivingBehavior = new DrivingBehavior();
- void drive() {
- this.drivingBehavior.Drive();
- }
- }
- public class Boat {
- private ISailingBehavior sailingBehavior = new SailingBehavior ();
- void sail() {
- this.sailingBehavior.Sail();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment