标签:适配器模式
package com.DesignPattern.Structural.Adapter;
public interface Target {
public void request();
}
package com.DesignPattern.Structural.Adapter;
//源角色
public class Adaptee {
// 原有业务处理
public void specificRequest() {
System.out.println("原有业务处理");
}
}
package com.DesignPattern.Structural.Adapter;
public class Adapter extends Adaptee implements Target {
@Override
public void request() {
super.specificRequest();
}
}
package com.DesignPattern.Structural.Adapter;
public class Client {
public static void main(String[] args){
//适配器模式应用
Target target=new Adapter();
target.request();
}
}
package com.DesignPattern.Structural.Adapter;
public class Dumplings {
public void makeDumplings(){
System.out.println("调馅");
System.out.println("擀皮");
System.out.println("包馅");
}
}
package com.DesignPattern.Structural.Adapter;
public interface Hundun {
public void makeHundun();
}
package com.DesignPattern.Structural.Adapter;
public class FoodAdapter extends Dumplings implements Hundun {
@Override
public void makeHundun() {
super.makeDumplings();
System.out.println("混沌和水饺一样都是用面包馅的食品");
}
}
package com.DesignPattern.Structural.Adapter;
public class ClientDemo {
public static void main(String[] args){
Hundun h=new FoodAdapter();
h.makeHundun();
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载|Copyright ©2011-2015,Supernatural, All Rights Reserved.
标签:适配器模式
原文地址:http://blog.csdn.net/williamfan21c/article/details/48088025