关于桥接模式的学习:
对于某些类型来说,有着多个维度的变化,那么应该如何面对这些多种变化呢?比如说,对于送一种什么什么礼物来说,鲜花是一种礼物,巧克力也是一种礼物;同样对于礼物来说,有着温和型的礼物,同样也有着热烈型的礼物。所以又该怎样表示这样的一种变化呢?
代码分析如下:
package com.lenovo.dp.bridge;
public class Test {
public static void main(String args []){
WarmGift wg = new WarmGift(new Flower());
}
}
class Gift{
GiftImpl impl;
}
class GiftImpl{
}
class Flower extends GiftImpl{
}
class WarmGift extends Gift{
public WarmGift(GiftImpl impl){
this.impl = impl;
System.out.println("实例化'温暖的花'这样一个对象");
}
}
对于这个模式来说,基本思想应该就是如上所示。