当前位置: 首页 > news >正文

写网站建设需求文档爱网之家下载

写网站建设需求文档,爱网之家下载,普通手机变营销手机系统,给别的公司提供网站建设一、引入 Object Oriented Adapters 二、XX 模式 aka:Wrapper (包装器) 2.1 Intent 意图 Convert the interface of a class into another interface clients expect. 将一个类的接口转换成客户希望的另外一个接口. 作为两个不兼容的接口之间的桥梁 适配器模式使…

一、引入

在这里插入图片描述

  • Object Oriented Adapters
    在这里插入图片描述
    在这里插入图片描述

在这里插入图片描述

二、XX 模式

aka:Wrapper (包装器)

2.1 Intent 意图

  • Convert the interface of a class into another interface clients expect. 将一个类的接口转换成客户希望的另外一个接口.
    • 作为两个不兼容的接口之间的桥梁
  • 适配器模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作

2.2 Applicability 适用性

  • You want to use an existing class, and its interface does not match the one you need.
  • you want to create a reusable class that cooperates with unrelated or unforeseen classes, that is, classes that don’t necessarily have compatible interfaces.
  • (object adapter only,仅对象适配器) you need to use several existing subclasses, but it’s impractical to adapt their interface by subclassing every one. 需要使用几个现有的子类,但是通过对每个子类进行子类化来适配它们的接口是不切实际的。
    • An object adapter can adapt the interface of its parent class. 对象适配器可以适配其(所有子类)父类的接口.

2.3 类图

  • 类适配器:多继承(not for java)、多实现
  • 对象适配器:关联,依赖组合

在这里插入图片描述

  • Client: Collaborates with objects conforming to the Target interface. 与符合目标接口的对象进行协作
  • Target: Defines the domain-specific interface that Client uses, It should be an interface. 定义 Client 使用的特定领域的接口,它应该是一个接口
  • Adaptee: Defines an existing interface that needs adapting, could be an interface, or abstract class, or class. 定义需要适配的现有接口,Adaptee 可以是接口、抽象类或类
  • Adapter: Adapts the interface of Adaptee to the Target interface. 适配 Adaptee 的接口到目标接口

2.4 实例:鸭子与火鸡

鸭子与火鸡:
If it walks like a duck and quacks like a duck, then it might be a turkey wrapped with a duck adapter
如果它像鸭子一样走路,那么它可能是一只带着鸭子适配器的火鸡

  • 鸭子
public interface Duck {public void quack();public void fly();
}
public class MallardDuck implements Duck {public void quack() {System.out.println("Quack");}public void fly() {System.out.println("I'm flying");}
}
  • 火鸡
public interface Turkey {public void gobble();public void fly();
}
public class WildTurkey implements Turkey {public void gobble() {System.out.println("Gobble gobble");}public void fly() {System.out.println("I'm flying a short distance");}
}
  • 火鸡适配器:适配火鸡接口
public class TurkeyAdapter implements Duck {Turkey turkey;public TurkeyAdapter(Turkey turkey) {this.turkey = turkey;}public void quack() {turkey.gobble();}public void fly() {for (int i = 0; i < 5; i++) {turkey.fly();}}
}
public class DuckTestDrive {public static void main(String[] args) {MallardDuck duck = new MallardDuck();WildTurkey turkey = new WildTurkey();Duck turkeyAdapter = new TurkeyAdapter(turkey);System.out.println("The Turkey says...");turkey.gobble();turkey.fly();System.out.println("\nThe Duck says...");testDuck(duck);System.out.println("\nThe TurkeyAdapter says...");testDuck(turkeyAdapter);}static void testDuck(Duck duck) {duck.quack();duck.fly();}
}

在这里插入图片描述

  • 鸭子适配器:适配鸭子
public class DuckAdapter implements Turkey {Duck duck;Random rand;public DuckAdapter(Duck duck) {this.duck = duck;rand = new Random();}public void gobble() {duck.quack();}public void fly() {if (rand.nextInt(5) == 0) {duck.fly();}}
}
public class TurkeyTestDrive {public static void main(String[] args) {MallardDuck duck = new MallardDuck();Turkey duckAdapter = new DuckAdapter(duck);for (int i = 0; i < 10; i++) {System.out.println("The DuckAdapter says...");duckAdapter.gobble();duckAdapter.fly();}}
}

在这里插入图片描述


在这里插入图片描述

2.5 实例:适配枚举到迭代器

The early collections types (Vector, Stack, Hashtable, and a few others) implement a method elements(), which returns an Enumeration.

Adapting an Enumeration to an Iterator.

  • Target:Iterator
  • Adaptee:Enumeration
  • Adapter:EnumerationIterator
@SuppressWarnings("unchecked")
public class EnumerationIterator implements Iterator {Enumeration enumeration;public EnumerationIterator(Enumeration enumeration) {this.enumeration = enumeration;}public boolean hasNext() {return enumeration.hasMoreElements();}public Object next() {return enumeration.nextElement();}public void remove() {throw new UnsupportedOperationException();}
}
public class EnumerationIteratorTestDrive {@SuppressWarnings("unchecked")public static void main (String args[]) {// Vector v = new Vector(Arrays.asList(args));Vector v = new Vector(Arrays.asList("A", "B", "C", "E", "F", "G"));Iterator iterator = new EnumerationIterator(v.elements());while (iterator.hasNext()) {System.out.println(iterator.next());}}
}

以迭代器形式遍历枚举。

http://www.yayakq.cn/news/227068/

相关文章:

  • 网站风险怎么解决方案wordpress 左导航
  • 昆明集团网站建设90设计怎么免费下载
  • 达州科创网站建设公司网站建设报价选兴田德润
  • 上海网站推广排名软件界面设计要求
  • 无锡网络科技有限公司网站优化需要工具
  • 合肥网站制作网站最近网站改版文章突然不收录
  • 虚拟机主机网站建设的几个步骤wordpress博客空间
  • 北海 网站建设 公司中国工程有限公司
  • 壹财富 网站开发怎么查在哪个网站做的备案
  • 房产类网站制作商网上购物网站开发
  • 如何做属于自己的网站东莞市建设企业网站企业
  • 阿里巴巴国际站可以做网站吗视频拍摄教程
  • 中小企业网站开发韵茵网站怎么做下拉刷新页面数据
  • 中国建设劳动学会监制网站seo优化sem推广
  • 公司网站开发费用兴田德润官方网站微信小程序开发工具教程
  • 自己做抽奖网站违法吗宣化网站建设
  • 做宣传海报的网站重庆网站建设优化排名
  • 光之翼可以做网站吗平台网站 备案吗
  • 做电商网站有什语言好东莞企业网站建立报价
  • 华为云建设网站需要域名吗wordpress update ftp
  • 打开百度竞价页面是网站是什么做新闻封面的网站
  • 网站公司优势上海猎头公司排名
  • 政务公开 网站建设移动网站设计
  • 硅谷主角刚开始做的是软件还是网站建设网站套餐
  • wordpress 目录排序广东seo推广贵不贵
  • 怎么做网站的浏览量统计太原网站seo顾问
  • 自己做的网站出现广告郑州做网站元辰
  • 旭泽建站有漏洞的网站
  • 专业的营销网站建设公司排名wordpress按钮编辑器
  • 广西网站建设营销公司网站收录作用