设计模式——适配器模式
来源:互联网 发布:淘宝店铺装修教程2016 编辑:程序博客网 时间:2024/06/11 12:44
类适配器
UML图:
target接口:
public interface Target {public void numberSort(double a[]);public void numberSort(int a[]);}
adaptee类:
public class Adaptee {public void numberSort(double a[]){double temp;for(int i=0; i<a.length; i++){for(int j=i; j<a.length; j++){if(a[i] > a[j]){temp = a[i];a[i] = a[j];a[j] = temp;}}}}}
adapter类:
public class ClassAdapterSort extends Adaptee implements Target{public void numberSort(int a[]){int n = a.length;double b[] = new double[n];for(int i=0; i<n; i++){b[i] = a[i] ;}this.numberSort(b);for(int i=0; i<n; i++){a[i] =(int) b[i];}}public void numberSort(double a[]){double temp;for(int i=0; i<a.length; i++){for(int j=i; j<a.length; j++){if(a[i] > a[j]){temp = a[i];a[i] = a[j];a[j] = temp;}}}}}
对象适配器:
UML图:
target接口:
public interface Target {public void numberSort(double a[]);public void numberSort(int a[]);}
adaptee类:
public class Adaptee {public void numberSort(double a[]){double temp;for(int i=0; i<a.length; i++){for(int j=i; j<a.length; j++){if(a[i] > a[j]){temp = a[i];a[i] = a[j];a[j] = temp;}}}}}
adapter类:
public class ObjectAdapterSort implements Target{private Adaptee adaptee = new Adaptee();public void numberSort(int a[]){int n = a.length;double b[] = new double[n];for(int i=0; i<n; i++){b[i] = a[i] ;}adaptee.numberSort(b);for(int i=0; i<n; i++){a[i] =(int) b[i];}}public void numberSort(double a[]){adaptee.numberSort(a);}}
0 0
- 设计模式—适配器模式
- 设计模式—适配器模式
- 设计模式—适配器模式
- 设计模式—适配器模式
- 设计模式—适配器模式
- 设计模式—适配器模式
- 设计模式—适配器模式
- 设计模式—适配器模式
- 设计模式——适配器
- 每日设计模式——适配器模式
- 浅谈设计模式——适配器模式
- 设计模式——适配器模式(Adapter)
- 设计模式—适配器模式—C++
- JAVA设计模式——适配器模式
- java设计模式——适配器模式
- 【大话设计模式】——适配器模式
- JAVA设计模式——适配器模式
- 设计模式——适配器模式
- 2014 百度笔试 机器学习及数据挖掘
- JavaWeb入门经典实例
- KMP算法
- OCP 1Z0 052 122
- 关于使用Transaction对于非数据库事务的操作
- 设计模式——适配器模式
- POI导出Exel表中图片到文件夹下
- CSDN 夏令营程序 试题分析 (3)
- nginx安装及启动
- poi获取Excel表中图片位置
- 修改MyEclipse行数的颜色
- spring mina整合(客户端进行调用)
- SQL语句集锦——数据库表查询、更新、删除等SQL语法
- 理解got和plt