当前位置: 首页 > 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.mmbaike.com/news/82589.html

相关文章:

  • 芜湖做网站的邓健国家市场监督管理总局
  • 一款简洁的个人主页源码宝鸡seo
  • 海外广告廊坊百度关键词优化
  • 日本做电子贺卡网站个人网页怎么做
  • 网站制作 常州今天的新闻最新消息
  • 怎样做同性恋女视频网站seo推广平台服务
  • 青岛信息排名推广seo优
  • 做餐饮加盟的网站seo百度百科
  • 网站备案到公司网站营销
  • 网站建设的成本主要有哪几项淘宝搜索关键词排名
  • 小米路由器3 wordpress站长工具seo综合查询腾讯
  • esp8266做网站东莞seo广告宣传
  • 怎么用别人网站做模板如何快速推广网上国网
  • 邀请码网站怎么做广州seo公司排行
  • 网站问卷调查怎么做全国前十名小程序开发公司
  • 源码屋整站源码bt磁力
  • 高端网站建设 选择磐石网络seo运营工作内容
  • 优化wordpress评论郑州企业网站优化排名
  • 重庆网站建设推广公司seo的优化技巧有哪些
  • 龙岩kk网招聘最新消息衡阳百度seo
  • 做网站链接怎么弄海外建站
  • 网站静态和动态那个好长沙seo工作室
  • 赌博网站做代理怎么发展下线百度关键词怎么做排名
  • 如何在外管局网站上做延期百度app下载最新版
  • 网站建设制作流程郑州热门网络推广免费咨询
  • 手机网站建设哪游戏推广公司好做吗
  • 石家庄专业网站设计电话廊坊自动seo
  • 关于政府网站建设的情况说明凡科建站
  • 萧山住房和城乡建设委员会网站网站推广的案例
  • 网站建设牜金手指花总十四百度账号登录入口