仿照<java与模式>中bridge模式的例子自己改写的一个例子:有N个飞机制造商(AirBus.....),每个飞机制造商有客机(PassenagerPlane)和货机(CargoPlane).....实现代码如下:1.飞机制造商抽象接口: interface IAirPlaneMaker } 2.飞机抽象接口 interface IAirPlane 3.飞机制造商的一个实现 class AirBus : IAirPlaneMaker } 4 飞机的实现 class PassengerPlane : IAirPlane } 5 通过这种bridge模式,客户端代码非常简洁 IAirPlaneMaker maker = new AirBus(); IAirPlane passPlane = maker.producePass(); passPlane.Fly(); 考虑:飞机制造商中生产飞机的方式不是很好,藕合度太高,如果要新增加一种飞机生产,则必须改变制造商接口极其所有实现子类。考虑使用工厂模式实现。。。。。 相关文章: 2021-12-06 2021-12-08 2021-12-24