- 1 using System;
- 2 using System.Collections.Generic;
- 3 using System.Linq;
- 4 using System.Text;
- 5
- 6 namespace BridgePattern
- 7 {
- 8 interface KindofPlane//Implementor
- 9 {
- 10 void CreatePlane();
- 11 }
- 12 class PassengerPlane : KindofPlane//ConcreteImplementorA
- 13 {
- 14
- 15 public void CreatePlane()
- 16 {
- 17 Console.WriteLine("Create Passenger Plane");
- 18 }
- 19 }
- 20 class CargoPlane : KindofPlane//ConcreteImplementorB
- 21 {
- 22
- 23 public void CreatePlane()
- 24 {
- 25 Console.WriteLine("Create Cargo Plane");
- 26 }
- 27 }
- 28 abstract class Plane//Abstraction
- 29 {
- 30 protected KindofPlane planekind;
- 31 public void setkind(KindofPlane planekind)
- 32 {
- 33 this.planekind = planekind;
- 34 }
- 35 public abstract void Create();
- 36
- 37 }
- 38 class Airbus : Plane//RefinedAbstraction
- 39 {
- 40 public override void Create()
- 41 {
- 42 Console.WriteLine("Airbus:");
- 43 planekind.CreatePlane();
- 44 }
- 45 }
- 46 class Boeing : Plane//RefinedAbstraction
- 47 {
- 48 public override void Create()
- 49 {
- 50 Console.WriteLine("Boeing:");
- 51 planekind.CreatePlane();
- 52 }
- 53 }
- 54 class McDonnell_Douglas : Plane//RefinedAbstraction
- 55 {
- 56 public override void Create()
- 57 {
- 58 Console.WriteLine("McDonnell_Douglas:");
- 59 planekind.CreatePlane();
- 60 }
- 61 }
- 62 class Program
- 63 {
- 64 static void Main(string[] args)
- 65 {
- 66 Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~");
- 67 KindofPlane passengerPlane = new PassengerPlane();
- 68 Airbus air = new Airbus();
- 69 air.setkind(passengerPlane);
- 70 air.Create();
- 71 Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~");
- 72 KindofPlane cargoPlane = new CargoPlane();
- 73 Boeing boe = new Boeing();
- 74 boe.setkind(cargoPlane);
- 75 boe.Create();
- 76 Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~");
- 77 KindofPlane cargpPlane2 = new CargoPlane();
- 78 McDonnell_Douglas mc= new McDonnell_Douglas();
- 79 mc.setkind(cargoPlane);
- 80 mc.Create();
- 81 Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~");
- 82 }
- 83 }
- 84 }