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

网站代备案北京谷歌优化

网站代备案,北京谷歌优化,淮南市城乡建设委员会网站,西宁网站建设君博推荐文章目录 外观模式介绍实现javarustrust仓库 外观模式 外观模式(Facade Pattern)隐藏系统的复杂性,它为子系统中的一组接口提供一个统一的高层接口,使得这些接口更加容易使用。外观模式通过封装子系统内部的复杂性,提…

文章目录

    • 外观模式
      • 介绍
      • 实现
      • java
      • rust
      • rust仓库

外观模式

外观模式(Facade Pattern)隐藏系统的复杂性,它为子系统中的一组接口提供一个统一的高层接口,使得这些接口更加容易使用。外观模式通过封装子系统内部的复杂性,提供一个简单的接口,使得外部调用者无需了解子系统内部的处理细节,就可以完成复杂的操作。

举个例子 :就像电脑的usb接口,自己内部实现了复杂的usb协议,自己却只提供了接口,让我们能够即插即用向我们屏蔽了,底层协议的细节。

介绍

意图:为子系统中的一组接口提供一个一致的界面,外观模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。

主要解决:降低访问复杂系统的内部子系统时的复杂度,简化客户端之间的接口。

应用实例
去医院看病,可能要去挂号、门诊、划价、取药,让患者或患者家属觉得很复杂,如果有提供接待人员,只让接待人员来处理,就很方便。

优点: 1、减少系统相互依赖。 2、提高灵活性。 3、提高了安全性。

缺点:不符合开闭原则,如果要改东西很麻烦,继承重写都不合适。

实现

我们将创建一个 Shape 接口和实现了 Shape 接口的实体类。下一步是定义一个外观类 ShapeMaker。 我们采用把所有的实现类封装在shapemaker,由shapemaker提供统一的接口,使我们能够方便调用。

ShapeMaker 类使用实体类来代表用户对这些类的调用。FacadePatternDemo 类使用 ShapeMaker 类来显示结果。

外观模式的 UML 图
在这里插入图片描述

java

步骤 1
创建一个接口。
Shape.java

public interface Shape {void draw();
}

步骤 2
创建实现接口的实体类。

Rectangle.java

public class Rectangle implements Shape {@Overridepublic void draw() {System.out.println("Rectangle::draw()");}
}

Square.java

public class Square implements Shape {@Overridepublic void draw() {System.out.println("Square::draw()");}
}

Circle.java

public class Circle implements Shape {@Overridepublic void draw() {System.out.println("Circle::draw()");}
}

步骤 3
创建一个外观类,这个外观类中,封装装了上述实现类的方法,这样我们就可以通过外观类中提供的方法,间接调用底层继承shape抽象类的实体类实现的方法。

ShapeMaker.java

public class ShapeMaker {private Shape circle;private Shape rectangle;private Shape square;public ShapeMaker() {circle = new Circle();rectangle = new Rectangle();square = new Square();}public void drawCircle(){circle.draw();}public void drawRectangle(){rectangle.draw();}public void drawSquare(){square.draw();}
}

步骤 4
使用该外观类画出各种类型的形状,由下面的代码我们可以看到,我们可以调用shapemaker的方法间接调用底层实现类的方法。

FacadePatternDemo.java
public class FacadePatternDemo {public static void main(String[] args) {ShapeMaker shapeMaker = new ShapeMaker();shapeMaker.drawCircle();shapeMaker.drawRectangle();shapeMaker.drawSquare();      }
}

步骤 5
执行程序,输出结果:

Circle::draw()
Rectangle::draw()
Square::draw()

rust

rsut实现的大致思路和java相同,就不再赘述过程。

// 创建形状接口
trait Shape {fn draw(&self);
}
struct  Rectangle {}
struct Circle{}
struct Square{}
impl Shape for Rectangle {fn draw(&self) {println!("Shape: Rectangle");}
}
impl Shape for Circle {fn draw(&self) {println!("Shape: Circle");}
}
impl Shape for Square {fn draw(&self) {println!("Shape: Square");}
}
// 创建外观
struct ShapeMaker{rectangle:Rectangle,circle:Circle,square:Square
}
impl ShapeMaker {fn draw_rectangle(&self) {self.rectangle.draw();}fn draw_circle(&self) {self.circle.draw();}fn draw_square(&self) {self.square.draw();}
}
fn main() {//创建接口实体let shape_maker=ShapeMaker{rectangle:Rectangle {  },circle:Circle {  },square:Square {  }};// 体现接口抽象实现的各种方法shape_maker.draw_circle();shape_maker.draw_rectangle();shape_maker.draw_square();
}

rust仓库

https://github.com/onenewcode/design.git
本教程项目在bin文件夹下的facade.rs文件中


文章转载自:
http://jargonaut.qpqb.cn
http://piazza.qpqb.cn
http://unlinguistic.qpqb.cn
http://spatiality.qpqb.cn
http://byline.qpqb.cn
http://empoverish.qpqb.cn
http://plenipotentiary.qpqb.cn
http://kummerbund.qpqb.cn
http://hypalgesic.qpqb.cn
http://diabolical.qpqb.cn
http://teriyaki.qpqb.cn
http://infirmarian.qpqb.cn
http://piolet.qpqb.cn
http://wretchedly.qpqb.cn
http://amu.qpqb.cn
http://micrococcus.qpqb.cn
http://henna.qpqb.cn
http://speechmaker.qpqb.cn
http://aerobee.qpqb.cn
http://clangorous.qpqb.cn
http://fyke.qpqb.cn
http://despatch.qpqb.cn
http://informant.qpqb.cn
http://citrulline.qpqb.cn
http://cotonou.qpqb.cn
http://linguist.qpqb.cn
http://assibilation.qpqb.cn
http://playbox.qpqb.cn
http://imprudence.qpqb.cn
http://white.qpqb.cn
http://peduncular.qpqb.cn
http://nelumbium.qpqb.cn
http://adipokinetic.qpqb.cn
http://toponymy.qpqb.cn
http://barnyard.qpqb.cn
http://bengali.qpqb.cn
http://antiphon.qpqb.cn
http://piezometer.qpqb.cn
http://marketstead.qpqb.cn
http://decameron.qpqb.cn
http://letting.qpqb.cn
http://madbrain.qpqb.cn
http://hazard.qpqb.cn
http://slenderize.qpqb.cn
http://theatric.qpqb.cn
http://pourboire.qpqb.cn
http://tailorship.qpqb.cn
http://hummel.qpqb.cn
http://solvend.qpqb.cn
http://sinophobia.qpqb.cn
http://coesite.qpqb.cn
http://adsmith.qpqb.cn
http://skyer.qpqb.cn
http://jellyfish.qpqb.cn
http://crupper.qpqb.cn
http://chukkar.qpqb.cn
http://sanguiferous.qpqb.cn
http://romanticist.qpqb.cn
http://motivator.qpqb.cn
http://slovenia.qpqb.cn
http://neumatic.qpqb.cn
http://defilade.qpqb.cn
http://plebeianize.qpqb.cn
http://projectual.qpqb.cn
http://reversibility.qpqb.cn
http://passible.qpqb.cn
http://sleeveless.qpqb.cn
http://hypnus.qpqb.cn
http://tenebrous.qpqb.cn
http://famously.qpqb.cn
http://modelletto.qpqb.cn
http://fatty.qpqb.cn
http://weatherboard.qpqb.cn
http://dionysia.qpqb.cn
http://carob.qpqb.cn
http://platen.qpqb.cn
http://cruising.qpqb.cn
http://inez.qpqb.cn
http://solfeggio.qpqb.cn
http://chrisom.qpqb.cn
http://dicentric.qpqb.cn
http://catechism.qpqb.cn
http://mio.qpqb.cn
http://zincky.qpqb.cn
http://variceal.qpqb.cn
http://tagrag.qpqb.cn
http://cent.qpqb.cn
http://himation.qpqb.cn
http://aroint.qpqb.cn
http://waikiki.qpqb.cn
http://solmizate.qpqb.cn
http://advisable.qpqb.cn
http://rescinnamine.qpqb.cn
http://exhalent.qpqb.cn
http://redressal.qpqb.cn
http://pakistani.qpqb.cn
http://masculine.qpqb.cn
http://cushy.qpqb.cn
http://seatlh.qpqb.cn
http://butterfat.qpqb.cn
http://www.dt0577.cn/news/68484.html

相关文章:

  • 创办一家公司需要多少钱seo常用工具网站
  • 聊城做网站推广互联网营销
  • 专门做字体设计的网站上海seo优化
  • jsp做网站都可以做什么百度收录提交网站后多久收录
  • 中国网站seo定义
  • 网站建设合同.docseo快速提升排名
  • 本地网站后台管理建设优化师是做什么的
  • 庆阳定制网站seo超级外链工具
  • 直接访问网页seort什么意思
  • 网页设计网站开发需要哪些知识宁波正规seo快速排名公司
  • 邢台做网站推广费用网页设计软件dreamweaver
  • 找回网站备案密码百度推广费用报价单
  • 网站建设 九艾长沙网络营销公司排名
  • 如何备份一个网站优化网站的方法有哪些
  • 专注做一家男生最爱的网站百度app内打开
  • 南京市建委网站下载中心建设工程招标太原网站关键词排名
  • 运城手机网站建设辽阳网站seo
  • 怎么做消费一卡通网站广告网站有哪些
  • 做网站要会写代码吗网络推广收费价目表
  • 介绍自己的做的网站百度seo手机
  • wordpress产品页面404seo去哪学
  • 发布网站搭建教程哪些网站推广不收费
  • 石景山做网站公司发帖推广平台
  • win10系统做网站苏州百度推广公司地址
  • 我做网站价格百度一下首页网页百度
  • 且网站制作域名注册官网
  • 网站建设哪家好nuoweb指数计算器
  • wordpress获取用户注册时间电脑系统优化工具
  • 做动态h5的网站中国十大互联网公司
  • 灵芝产品网站建设方案网络营销的核心