简述:
Adapter模式
需求:
有一个Adaptee类,有一个方法是SpecificRequest()但是,由于系统要求接口统一为Request(),同时又不修改原先Adaptee类的方法,
于是,只能用Adapter模式设计一个Adapter类来统一这个接口
代码:
Adaptee.java
package design_pattern.adapter; public class Adaptee { public void SpecificRequest(){ System.out.println("Specific Request"); } }
package design_pattern.adapter; public class Adapter extends Adaptee { Adaptee adaptee = new Adaptee(); public void Request(){ adaptee.SpecificRequest(); } }
package design_pattern.adapter; public class Test { public static void main(String[] args) { Adapter adapter = new Adapter(); adapter.Request(); } }