定义:
将两个不兼容的类纠合在一起使用,属于结构型模式,需要有Adaptee(被适配者)和Adaptor(适配器)两个身份
适用范围:
一般是需要复用两个或两个以上的类或接口中的某些方法.
package test;
import java.util.List;
public class Client {
public int getClienCount(){
return 1000;
}
/**
*
* orther month .....
*
*/
}
package test;
import java.util.List;
public class Employee {
public int getEmployeeCount(){
return 100;
}
/**
*
* orther month .....
*
*/
}
//如果我门需要Client 中的getClienCount(),Employee 中的getEmployeeCount()方法
package test.adapter;
public interface IEmployee {
public int getEmployeeCount();
}
package test.adapter.impl;
import test.Client;
import test.Employee;
import test.adapter.IEmployee;
public class EmployeeImpl extends Client implements IEmployee{
private Employee employee;
public EmployeeImpl(Employee employee){
this.employee = employee;
}
public int getEmployeeCount() {
return employee.getEmployeeCount();
}
public int getClientCount(){
return super.getClienCount();
}
}
//这样我们就在不改变某些类原代码 或在不知道源代码的情况下,成功的提取了类中的某些方法
package test.adapter;
import test.Employee;
import test.adapter.impl.EmployeeImpl;
public class AdapterTest {
public static void main(String args[]){
EmployeeImpl empl = new EmployeeImpl(new Employee());
System.out.println("eCount: " + empl.getClienCount());
System.out.println("cCount: " + empl.getEmployeeCount());
}
}
分享到:
相关推荐
java 汽车适配器(Adapter适配器模式) java 汽车适配器(Adapter适配器模式)
NULL 博文链接:https://chaimzane.iteye.com/blog/337467
这个是我写的一个自定义Adapter适配器,用来绑定数据到ListView上。我写的代码非常简单易懂
C#面向对象设计模式纵横谈(7):Adapter 适配器模式(结构型模式) 体验课程
C#面向对象设计模式纵横谈(7):Adapter 适配器模式(结构型模式) (Level 300)
Adapter适配器模式在JavaScript设计模式编程中的运用分析_.docx
该工程师ec项目,是一个通用的listview/gridview的适配器
在这里与各位分享本人从网络上下载的C#面向对象设计模式纵横谈系列视频,共有25节,除了第一节需要各位贡献一点资源分以作为对本人上传资源的回馈,后面的其他资源均不需要... 这是第7节:结构型模式Adapter 适配器模式
C#面向对象设计模式 Adapter 适配器模式 视频讲座下载
通用的RecyclerView Adapter类,以及实例代码。
本程序实现了android登录功能以及list的adapter列表功能
主要为大家详细介绍了Java设计模式之Adapter适配器模式,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
主要介绍了Python设计模式编程中Adapter适配器模式的使用实例,一般来说适配器模式可以细分为类适配器和对象适配器模式,需要的朋友可以参考下
适配器模式的作用是解决两个软件实体间的接口不兼容的问题,在JavaScript尤其是AJAX方面比较常用,接下来看一下对Adapter适配器模式在JavaScript设计模式编程中的运用分析
万能Adapter数据适配器,
主要介绍了Java 适配器模式(类适配器,对象适配器)优缺点对比的相关资料,java 适配器在基础知识中还是比较重要的,这里就说下如何使用,需要的朋友可以参考下
listView删除与刷新适配器的例子,看了此例子基本就会做项目了
android adapter适配器详解