首页 > 其他 > 详细

design_model(5)adapter

时间:2018-08-29 16:39:46      阅读:184      评论:0      收藏:0      [点我收藏+]

1.适配器模式

将一个类的接口转换成客户希望的另外一个接口。Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以在一起工作。//用一个处理方法区匹配相同接口不同实现下的相同的方法名

技术分享图片

2.实例

 

public  interface Adapter {
	public abstract void  test() ;
}

public class Adaptee  implements  Adapter{
	@Override
	public void  test() {
		
	}
}

public  interface  Target {
   public  abstract void  handler();
}

public class TargetImp   implements  Target{
	private  Adapter adapter;
	@Override
	public void handler() {
		adapter.test();
	}
	public TargetImp(Adapter adapter) {
		super();
		this.adapter = adapter;
	}
}

public class Client {
	  public static void main(String[] args) {
		 Adaptee adaptee = new Adaptee();
		 TargetImp targetImp = new TargetImp(adaptee);
		 targetImp.handler();
	  }
}

 

design_model(5)adapter

原文:https://www.cnblogs.com/gg128/p/9555101.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!