仿照<java与模式>中bridge模式的例子自己改写的一个例子:
有N个飞机制造商(AirBus.....),每个飞机制造商有客机(PassenagerPlane)和货机(CargoPlane).....实现代码如下:
1.飞机制造商抽象接口:
一个Bridge模式的例子    interface IAirPlaneMaker
    }
2.飞机抽象接口
一个Bridge模式的例子interface IAirPlane
3.飞机制造商的一个实现
一个Bridge模式的例子class AirBus : IAirPlaneMaker
    }
4 飞机的实现
一个Bridge模式的例子class PassengerPlane : IAirPlane
    }
5 通过这种bridge模式,客户端代码非常简洁
一个Bridge模式的例子 IAirPlaneMaker maker = new AirBus();
一个Bridge模式的例子            IAirPlane passPlane 
= maker.producePass();
一个Bridge模式的例子            passPlane.Fly();

考虑:飞机制造商中生产飞机的方式不是很好,藕合度太高,如果要新增加一种飞机生产,则必须改变制造商接口极其所有实现子类。考虑使用工厂模式实现。。。。。

相关文章:

  • 2021-12-06
  • 2021-12-08
  • 2021-12-24
猜你喜欢
  • 2022-02-01
  • 2021-10-30
  • 2022-12-23
  • 2021-12-19
  • 2022-03-06
  • 2021-09-14
  • 2021-12-02
相关资源
相似解决方案