结构型模式主要有:
1.适配器模式
2.外观模式
3.装饰模式
4.桥接模式
5.组合模式
6.享元模式
7.代理模式
1.适配器模式
分为类适配器和对象适配器
类适配器
用一个具体的Adapter类对Adaptee和Target进行匹配,Adapter类多重继承Adaptee和Target类
Adapter可重定义Adaptee的部分行为,因为Adapter是Adaptee的一个子类
示例:
//Target:定义Client使用的与特定领域相关的接口
public interface Target
{ void request(); }
//Adaptee:现在需要适配的已经存在的接口
public class Adaptee
{
public void specificRequest(){}
}
//Adapter:对Adaptee