菜鸟硕枫设计模式系列之7 适配器模式
适配器模式,正如适配器这个名字一样,起一个转换的作用。目的是通过接口转化,使得新系统和老系统可以正常交互。适配器模式是一种结构型模式。
适配器模式类图:
具体实现demo:
新系统:
package adapterPattern;public class AdapterPatternTest{public static void main(String[] args){OldSystemImpl oldSystem = new OldSystemImpl();NewSystemImpl newSystemImpl = new NewSystemImpl();Adapter adapter = new Adapter();newSystemImpl.doAnotherthing(adapter.convertMethod(oldSystem.doSomething()));}}