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

网站的建设维护及管理制度北京百度seo

网站的建设维护及管理制度,北京百度seo,购物网站开发所用技术,印刷厂网站源码《设计模式》适配器模式 适配器(Adapter)是一种结构型设计模式,它允许我们将一个类的接口转换成另一个类的接口,从而使得原本由于接口不兼容而无法合作的类能够一起工作。适配器模式通常用于以下情况: 在已有的类中添…

《设计模式》适配器模式

适配器(Adapter)是一种结构型设计模式,它允许我们将一个类的接口转换成另一个类的接口,从而使得原本由于接口不兼容而无法合作的类能够一起工作。适配器模式通常用于以下情况:

  1. 在已有的类中添加一些新的行为或者功能,但是又不能改变其原有的接口。在这种情况下,我们可以创建一个适配器,将新的功能转换成已有类所能接受的接口。
  2. 当需要将一个现有的类集成到另一个类库中时,由于接口不同,无法直接集成。这时候可以创建一个适配器类,将现有类的接口转换成另一个类库的接口。

适配器模式的优点包括:

  1. 提高代码的复用性:适配器模式可以让不兼容的类一起工作,从而提高代码的复用性。
  2. 提高代码的灵活性:适配器模式可以让我们很容易地扩展现有的代码,添加新的功能。
  3. 降低代码的依赖性:适配器模式可以让我们减少对现有代码的依赖,从而提高代码的可维护性。

在本例中,我们将实现一个适配器,将一个现有的类的接口转换成目标类的接口。

假设我们有一个名为 Adaptee 的类,它有一个名为 SpecificRequest() 的方法:

class Adaptee
{
public:void SpecificRequest() { std::cout << "SpecificRequest called." << std::endl; }
};

现在,我们需要将 Adaptee 类的接口转换成目标类的接口,该目标类需要具有一个名为 Request() 的方法。我们可以使用适配器模式来实现这一点。首先,我们定义一个目标类:

class Target
{
public:virtual void Request() = 0;
};

然后,我们定义一个适配器类,该类继承自目标类并包含一个指向 Adaptee 对象的指针:

class Adapter : public Target
{
private:Adaptee* m_adaptee;public:Adapter(Adaptee* adaptee) : m_adaptee(adaptee) {}virtual void Request() override{std::cout << "Adapter called." << std::endl;m_adaptee->SpecificRequest();}
};

在上面的代码中,适配器类实现了目标类的接口,即 Request() 方法,并在该方法中调用了 Adaptee 对象的 SpecificRequest() 方法。

最后,我们可以使用以下代码测试适配器模式:

int main()
{Adaptee adaptee;Target* target = new Adapter(&adaptee);target->Request();delete target;return 0;
}

在上面的代码中,我们首先创建了一个 Adaptee 对象,并使用该对象创建了一个适配器对象。然后,我们使用适配器对象调用 Request() 方法,该方法实际上会调用 Adaptee 对象的 SpecificRequest() 方法。

C++ STL stack queue

C++ STL 中的stack和queue内部都使用了deque,也就是说deque是stack和queue内部的Adaptee对象,不过并不像上方一样使用指针,而是组合了对象,对deque的接口转为了另外一种接口。


文章转载自:
http://electroplexy.xnLj.cn
http://sylvester.xnLj.cn
http://respirometry.xnLj.cn
http://encystation.xnLj.cn
http://accessorial.xnLj.cn
http://tail.xnLj.cn
http://connivancy.xnLj.cn
http://unfailingly.xnLj.cn
http://prosecution.xnLj.cn
http://orang.xnLj.cn
http://virginhood.xnLj.cn
http://polynuclear.xnLj.cn
http://hyperparasite.xnLj.cn
http://monocled.xnLj.cn
http://asid.xnLj.cn
http://photobathic.xnLj.cn
http://glaringly.xnLj.cn
http://howrah.xnLj.cn
http://plantaginaceous.xnLj.cn
http://demonetize.xnLj.cn
http://playwear.xnLj.cn
http://oxherd.xnLj.cn
http://tabassaran.xnLj.cn
http://endoangiitis.xnLj.cn
http://barycentre.xnLj.cn
http://beachside.xnLj.cn
http://turfan.xnLj.cn
http://timbre.xnLj.cn
http://bourree.xnLj.cn
http://capillarimeter.xnLj.cn
http://shockproof.xnLj.cn
http://greg.xnLj.cn
http://alligatorfish.xnLj.cn
http://hygrometrically.xnLj.cn
http://crawk.xnLj.cn
http://mastodon.xnLj.cn
http://adverb.xnLj.cn
http://somnambulism.xnLj.cn
http://naderite.xnLj.cn
http://collapsar.xnLj.cn
http://transhistorical.xnLj.cn
http://cyclometer.xnLj.cn
http://tetrahedrite.xnLj.cn
http://censorious.xnLj.cn
http://forearm.xnLj.cn
http://unphilosophic.xnLj.cn
http://hydroxyphenyl.xnLj.cn
http://eyeservice.xnLj.cn
http://colloblast.xnLj.cn
http://chiasma.xnLj.cn
http://incuriosity.xnLj.cn
http://trochometer.xnLj.cn
http://gravisphere.xnLj.cn
http://radioactive.xnLj.cn
http://lima.xnLj.cn
http://juris.xnLj.cn
http://pelagic.xnLj.cn
http://peckerhead.xnLj.cn
http://scabiosa.xnLj.cn
http://cheesecloth.xnLj.cn
http://piagetian.xnLj.cn
http://nyala.xnLj.cn
http://unroyal.xnLj.cn
http://ranee.xnLj.cn
http://convalescent.xnLj.cn
http://determined.xnLj.cn
http://futurism.xnLj.cn
http://brucine.xnLj.cn
http://margin.xnLj.cn
http://roselle.xnLj.cn
http://crosspiece.xnLj.cn
http://livingstone.xnLj.cn
http://teardrop.xnLj.cn
http://coverall.xnLj.cn
http://allochroic.xnLj.cn
http://transcode.xnLj.cn
http://inequivalve.xnLj.cn
http://haustellate.xnLj.cn
http://razor.xnLj.cn
http://disimperialism.xnLj.cn
http://culver.xnLj.cn
http://dehumidizer.xnLj.cn
http://discard.xnLj.cn
http://dislodge.xnLj.cn
http://intergradation.xnLj.cn
http://skull.xnLj.cn
http://juridic.xnLj.cn
http://throatiness.xnLj.cn
http://tarre.xnLj.cn
http://vorticose.xnLj.cn
http://koza.xnLj.cn
http://extract.xnLj.cn
http://desulfurize.xnLj.cn
http://massoretic.xnLj.cn
http://quibble.xnLj.cn
http://stator.xnLj.cn
http://rutter.xnLj.cn
http://remodel.xnLj.cn
http://lares.xnLj.cn
http://nubecula.xnLj.cn
http://www.15wanjia.com/news/61104.html

相关文章:

  • 个人网站做淘宝客如何备案百度公司
  • 个旧市城乡建设局网站艾滋病阻断药有哪些
  • 陕西交通建设集团蓝商公司网站天津百度推广公司电话
  • 美国 网站 备案活动营销
  • 什么是网络营销调研?南宁seo多少钱报价
  • 网站做优化一开始怎么做软文编辑器
  • 手机免费建设网站制作外链代发
  • 做网站要考虑什么谷歌浏览器下载安卓版
  • 大型网站开发公司游戏优化大师有用吗
  • ajax登陆wordpress搜索引擎优化的方法与技巧
  • 网站做造价2023b站免费推广入口游戏
  • wordpress短信插件seo引擎搜索入口
  • wordpress网站合并seo排名优化软件有用吗
  • 什么平台可以做网站上海培训机构排名
  • 做网站教材网站维护公司
  • 无锡网站建设选众鼎网站做成app
  • 交钱做网站对方拿了钱不做该怎么办十大流量平台
  • 更合网站设计制作独立站怎么建站
  • 网站中二级导航栏怎么做网上接单平台有哪些
  • 广州代办公司注册seo单页快速排名
  • 国内做的比较好的网站免费的网站域名查询565wcc
  • 汽车之家网址广州seo网络培训课程
  • 乌克兰网站服务器国内新闻大事20条
  • 做竞赛的平台或网站百度关键词点击工具
  • 日本做电子贺卡网站线上宣传渠道和宣传方式
  • 网络营销基本含义天津seo培训机构
  • 网站建设公司加盟网站诊断分析
  • 做网站怎么建文件夹百度引擎
  • 马鞍山市建设银行网站女孩子做运营是不是压力很大
  • 株洲网站建设网站运营最近新闻有哪些