scrapy立面parse

重点 (Top highlight)

定义 (Definition)

‘Facade’ pattern is a structural design pattern which improves the structure of a large system¹. Structural pattern is useful for making independent developed systems work together.

立面模式 是一种结构设计模式,可改善大型系统的结构¹。 结构模式对于使独立开发的系统协同工作非常有用。

The ‘Facade’ pattern defines an object representing a subsystem. This object is an interface that will take the responsibility to interact with the subsystem.

“外观”模式定义了一个代表子系统的对象。 该对象是一个接口,将负责与子系统进行交互。

[1] A system is composed of subsystems. A subsystem contains an interface and encapsulates classes. A class contains states and operations.

[1]一个系统由子系统组成。 子系统包含一个接口并封装类。 一个类包含状态和操作。

我们什么时候应该使用这种模式? (When should we use this pattern?)

提供到复杂子系统的简单接口 (To provide a simple interface to a complex subsystem)

This pattern should be used when it is possible to provide a simpler interface than the one provided by the existing subsystem. A complex subsystem needs to work in a specific way in order to work correctly. Moving this complexity to an interface simplifies the use of its functionalities. This interface, called a facade, hides the complexity from the client.

当可以提供比现有子系统提供的接口更简单的接口时,应使用此模式。 复杂的子系统需要以特定的方式工作才能正常工作。 将此复杂性移至接口可简化其功能的使用。 这个称为外观的界面向客户端隐藏了复杂性。

使子系统与客户端和其他子系统分离 (To decouple the subsystem from clients and other subsystems)

This pattern should be used when a system has many dependent¹ subsystems. It decouples their implementation details. It reduces dependencies and makes the code easier to use, understand, maintain and test.

当系统具有多个从属子系统时,应使用此模式。 它解耦了它们的实现细节。 它减少了依赖性,并使代码更易于使用,理解,维护和测试。

定义子系统的入口点 (To define an entry point to a subsystem)

This pattern should be used when subsystems are interdependent². Instead of exposing a client to a library, a framework, or a set of classes and their APIs, the facade pattern only exposes a simple unified API. Subsystems implement functionalities without knowing about the facade. They interact with each other within the system. So, the implementation details from the subsystems can change without impacting the facade API. It does not need any changes since a facade deals with interfaces and not implementations. It adds a layer of abstraction (the entry point) to improve the usability, readability and architecture of the code.

当子系统相互依赖²时,应使用此模式。 外观模式没有将客户端暴露给库,框架或一组类及其API,而是仅公开了一个简单的统一API。 子系统在不了解外观的情况下实现功能。 它们在系统内相互交互。 因此,子系统的实现细节可以更改,而不会影响Facade API。 因为外观处理接口而不是实现,所以不需要任何更改。 它增加了一个抽象层(入口点)以提高代码的可用性,可读性和体系结构。

[1] Dependent subsystems mean that a system has a dependency/reference on another system.

[1]依赖子系统是指一个系统对另一个系统具有依赖/引用。

[2] Interdependent subsystems mean that a system relies on another system in order to work.

[2]相互依赖的子系统意味着一个系统依赖于另一个系统才能工作。

我们应该如何使用这种模式? (How should we use this pattern?)

A client communicates with a subsystem through a facade. It is a simple interface that delegates the work to the appropriate subsystem.

客户端通过立面与子系统进行通信。 这是一个简单的界面,可将工作委托给相应的子系统。

image from Head First Design Patterns by Eric Freeman, Elisabeth Freeman, Kathy Sierra and Bert Bates
图片来自Eric Freeman,Elisabeth Freeman,Kathy Sierra和Bert Bates的Head First Design Patterns

If the subsystem classes can be highly-decoupled, following the Single Responsibility Principle and applying design patterns, we end up with a lot of smaller and smaller components. It makes them more reusable and easier to customize. However, depending on the number of components and the complexity of the task to achieve, it becomes harder and harder to use them.️ It might be difficult for the client to complete the task. The reason why we use the facade pattern is because it provides a simple view of the subsystem to the client.

如果子系统类可以高度分离,遵循“ 单一职责原则”并应用设计模式,那么最终我们会得到越来越小的组件。 它使它们更可重用且更易于自定义。 但是,取决于组件的数量和要完成的任务的复杂性,使用它们变得越来越难。️客户可能很难完成任务。 我们使用外观模式的原因是因为它为客户端提供了子系统的简单视图。

具体例子 (Concrete example)

Let’s say we have a home theater system that controls devices such as a DVD player, a projector… Here is the UML diagram reflecting the structure above.

假设我们有一个家庭影院系统,可以控制DVD播放器,投影仪等设备。这是反映上述结构的UML图。

We have a complex system with multiple classes interacting with each other. Before having a facade, the client had to directly interact with all of the appropriate functionalities/classes in order to start a movie for example. An analogy is to think about the facade as a remote controller.

我们有一个复杂的系统,其中多个类相互交互。 在拥有立面之前,客户必须直接与所有适当的功能/类进行交互才能开始播放电影。 类推是将立面视为遥控器。

实作 (Implementation)

To implement the facade, we create a facade object with subsystem objects.

为了实现外观,我们创建带有子系统对象的外观对象。

“立面”实施 (‘Facade’ Implementation)

class HomeTheaterFacade {private let amp: Amplifierprivate let tuner: Tunerprivate let dvd: DvdPlayerprivate let cd: CdPlayerprivate let projector: Projectorprivate let lights: TheaterLightsprivate let screen: Screenprivate let popper: PopcornPopper    init(_ amp: Amplifier,_ tuner: Tuner,_ dvd: DvdPlayer,_ cd: CdPlayer,_ projector: Projector,_ lights: TheaterLights,_ screen: Screen,_ popper: PopcornPopper) {self.amp = ampself.tuner = tunerself.dvd = dvdself.cd = cdself.projector = projectorself.lights = lightsself.screen = screenself.popper = popper    }    // MARK: Facade methods   func watchMovie(movie: String) {        print("Get ready to watch a movie...")        popper.on()        popper.pop()        lights.dim(10)        screen.down()        projector.on()        projector.wideScreenMode()        amp.on()        amp.setDvd(dvd)        amp.setSurroundSound()        amp.setVolume(5)        dvd.on()        dvd.play(movie)    }        // other methods here}

We compose our facade through constructor injection to give the facade all of the components it needs from the subsystem.

我们通过构造函数注入来构造外观,从而为外观提供子系统需要的所有组件。

客户实施 (Client Implementation)

// instantiate components herelet homeTheater = HomeTheaterFacade(amp, tuner, dvd, cd, projector, lights, screen, popper)homeTheater.watchMovie(movie: "Raiders of the Lost Ark")

Here, the client communicates with the subsystem through a simplified interface while another client can still fully use the functionality of the subsystem.

在这里,客户端通过简化的界面与子系统通信,而另一个客户端仍可以完全使用子系统的功能。

在操场上运行代码 (Run code in a Playground)

Here is an Online Swift Playground so an Xcode Playground does not have to be created in order to test this implementation of the ‘Facade’ pattern. Then, copy the code below that corresponds with the full implementation of the ‘Facade’ pattern for our home theater system.

这是一个在线Swift Playground,因此不必为了测试“ Facade”模式的实现而创建Xcode Playground。 然后,复制下面与家庭影院系统“门面”模式的完整实现相对应的代码。

class Amplifier {var tuner: Tunervar dvdPlayer: DvdPlayervar cdPlayer: CdPlayer    init(tuner: Tuner,         dvdPlayer: DvdPlayer,         cdPlayer: CdPlayer) {self.tuner = tunerself.dvdPlayer = dvdPlayerself.cdPlayer = cdPlayer    }    func on() {         print("Amplifier on")     }    func setDvd(_ dvd: DvdPlayer) {        print("Amplifier setting DVD player")     }    func setSurroundSound() {        print("Amplifier surround sound on")     }    func setVolume(_ volume: Int) {        print("Amplifier setting volume to \(volume)")     }    // other Amplifier methods...}class DvdPlayer {var movie: String = ""    func on() {         print("DVD Player on")     }    func play(_ movie: String) { self.movie = movie        print("DVD PLayer playing \"\(movie)\"")    }    // other DvdPlayer methods...}class TheaterLights {func dim(_ level: Int) {         print("Theater Ceiling Lights dimming to \(level)%")     }    func on() {         print("Theater Ceiling Lights on")     }    // other TheaterLights methods...}class Projector {var dvdPlayer: DvdPlayer    init(dvdPlayer: DvdPlayer) {self.dvdPlayer = dvdPlayer    }    func on() {         print("Projector on")     }    func wideScreenMode() {         print("Projector in widescreen mode (16x9 aspect ratio)")     }    // other Projector methods...}class Tuner {    // Tuner methods...}class Screen {func down() {         print("Theater Screen going down")     }    // other Screen methods...}class PopcornPopper {func on() {        print("Popcorn Popper on")     }    func pop() {         print("Popcorn Popper popping popcorn!")     }    // other PopcornPopper methods...}class CdPlayer {    // CdPlayer methods...}class HomeTheaterFacade {private let amp: Amplifierprivate let tuner: Tunerprivate let dvd: DvdPlayerprivate let cd: CdPlayerprivate let projector: Projectorprivate let lights: TheaterLightsprivate let screen: Screenprivate let popper: PopcornPopper    init(_ amp: Amplifier,_ tuner: Tuner,_ dvd: DvdPlayer,_ cd: CdPlayer,_ projector: Projector,_ lights: TheaterLights,_ screen: Screen,_ popper: PopcornPopper) {self.amp = ampself.tuner = tunerself.dvd = dvdself.cd = cdself.projector = projectorself.lights = lightsself.screen = screenself.popper = popper    }    // MARK: Facade methods    func watchMovie(movie: String) {        print("Get ready to watch a movie...")        popper.on()        popper.pop()        lights.dim(10)        screen.down()        projector.on()        projector.wideScreenMode()        amp.on()        amp.setDvd(dvd)        amp.setSurroundSound()        amp.setVolume(5)        dvd.on()        dvd.play(movie)    }    // other methods here...}// instantiate components herelet tuner = Tuner()let dvd = DvdPlayer()let cd = CdPlayer()let amp = Amplifier(tuner: tuner, dvdPlayer: dvd, cdPlayer: cd)let projector = Projector(dvdPlayer: dvd)let screen = Screen()let lights = TheaterLights()let popper = PopcornPopper()let homeTheater = HomeTheaterFacade(amp, tuner, dvd, cd, projector, lights, screen, popper)homeTheater.watchMovie(movie: "Raiders of the Lost Ark")

Finally, paste and run the code.

最后,粘贴并运行代码。

翻译自: https://levelup.gitconnected.com/facade-pattern-in-swift-11b5b7af7d4b

scrapy立面parse


http://www.taodudu.cc/news/show-5994820.html

相关文章:

  • 结构设计模式:立面模式
  • 结构模式:立面
  • 对计算机系美好期望,“共同进步,畅想美好未来”——计算机工程系举办第二届优秀校友经验分享会...
  • avue-crud自带的打印功能BUG,在打印时会打印操作栏
  • Axure原型——《瑶族非遗服饰App》
  • OpenAI 的外包数据标注员,时薪不足2美元,称工作是“精神创伤”
  • 实现选择图片时的灰色选中效果
  • 与服务器交互 【转载】 夕小瑶https://www.jiqizhixin.com/articles/2018-07-02-15
  • Js事件绑定时,函数名加括号和不加括号有什么区别
  • python运行不了、显示警告_如何消除Shell运行时显示的警告MatplotlibDeprecationWarning?...
  • 在设计PCB时需要注意的这些问题
  • 【LSTM预测】基于卷积神经网络结合双向长短时记忆CNN-BiLSTM(多输入单输出)数据预测含Matlab源码
  • 郭书瑶的故事
  • 瑶镶富资深用户给大家分享现在自媒体普遍的运营模式
  • 2022暑期实习笔试题总结(网易,华为,360,美团)
  • python爬虫的使用——成语接龙小游戏
  • 成语哲理浅析
  • 实战Go语言:基于开源数据的成语应用-欧阳桫-专题视频课程
  • Java画圆章
  • 1月干货总结:EasyDL上线时序预测模型,文档翻译全新发布
  • 产品升级|1月解锁50多项新功能
  • html中字在圆形上怎么写代码,绘制圆形在文档里面
  • 达观OCR文字识别赋能公积金中心实现业务办理再提速
  • 计算机网络实用技术教程txt,计算机网络实用技术教程 吕政.pdf
  • QT 基本图形绘制
  • 博客直通车
  • Qt基本图形绘制(圆、圆角矩形、圆弧、椭圆、扇形等)
  • [开源] 分享导出博客园文章成本地 Markdown 文件存储的工具
  • 用Java实现支持圆形带五角星 方形电子印章
  • 圆章能随便刻吗_企业公章能是随便刻的吗

scrapy立面parse_立面模式在Swift相关推荐

  1. scrapy立面parse_立面设计模式–设计观点

    scrapy立面parse 在上一篇文章中,我们描述了适配器设计模式 . 在今天的文章中,我们将介绍另一种类似的"四结构帮派"模式 . 顾名思义,结构模式用于从许多不同的对象形成更 ...

  2. 设计模式-(9)中介者模式(swift)

    在对象去耦合的模式中,有两种模式:中介者模式,观察者模式 一,概念 用一个中介对象来封装一系列的对象交互.中介者使各对象不需要显式地相互引用,从而使其耦合松散,而且可以独立地改变它们之间的交互. 这个 ...

  3. 设计模式之 Vistor 访问者模式:Swift 实现

    Vistor Mode: 访问者模式 访问者在获得权限的之后,可以访问被访者的各项内容,同时,不能影响到被访者的属性,这样才是一个文明的访问者. Visitor mode can isolate th ...

  4. 《从零开始学Swift》学习笔记(Day 52)——Cocoa错误处理模式

    Swift错误处理模式,在Swift1.x和Swift 2.0是不同的两种模式. Swift 1.x代码错误处理模式采用Cocoa框架错误处理模式,到现在Objective-C还沿用这种处理模式,而S ...

  5. swift 听筒模式_Swift的建设者模式

    swift 听筒模式 If you've ever faced an init with too many parameters or objects whose creation is dictat ...

  6. Python爬虫框架Scrapy学习笔记原创

    字号 scrapy [TOC] 开始 scrapy安装 首先手动安装windows版本的Twisted https://www.lfd.uci.edu/~gohlke/pythonlibs/#twis ...

  7. Swift和R3联手了,跨境支付市场竞争升级

    本周三,全球银行支付网络SWIFT CEO Gottfried Leibbrandt在巴黎金融科技论坛上宣布:将会与区块链企业R3一起合作,将R3的平台与其新的支付标准框架GPI整合在一起. 合作背景 ...

  8. 爬虫-豆瓣书籍排行榜及用户信息-2021.7.23-使用Scrapy框架-用MongoDB存储数据

    1.环境 python3.8或python3.7 pycharm2021.2 MongoDB Scrapy 2.信息提取 2.1 创建Scrapy项目 在cmd模式下创建Scrapy项目 # 进入要存 ...

  9. Scrapy简明教程(一)

    原文链接 前言 Scrapy是一个纯Python语言实现的爬虫框架,简单.易用.拓展性高使得其成为Python爬虫中的主流利器,本文以目前官方最新的版本1.6为基础,展开从简单使用到深入原理的探讨. ...

最新文章

  1. python 动态类型检测 性能_4种速度最慢的动态编程语言,你一定用过
  2. mysql创建的是拉丁_将MySQL数据库从拉丁转换为UTF-8
  3. [vue] 怎么在watch监听开始之后立即被调用?
  4. android手机可以设置屏幕锁定,安卓手机屏幕锁设置方法(九个点图案)
  5. Android系统(76)---ART和Dalvik区别
  6. oracle ||#039; where #039;||condition;,帝国cms后台添加字段提示#039;Row size too large. The maximum row size...
  7. 简单介绍基于颜色的阴影检测算法
  8. 高德上线“查岗功能”,你会监视另一半吗?精确到米的那种
  9. 推鹿是什么?推鹿介绍,推鹿是什么平台?
  10. springBoot做后台实现微信小程序图片上传和下载
  11. Springboot集成MybatisPlus、Druid
  12. linux中 kill USR1和USR2 的区别
  13. 华硕无线路由打印机服务器,彻底了解WL-500g型的华硕无线网络路由器
  14. 关于Loadlibrary 失败-找不到指定模块126错误
  15. 【源码】王者装逼工具/提升几倍的等级战力
  16. 字符类型与Unicode 编码
  17. android屏蔽表情输入法,Android中EditText屏蔽第三方输入法表情的方法示例
  18. 因子分析(factor analyis)
  19. java中jar文件
  20. 边打包边压缩边传输边解压

热门文章

  1. 中海岸不干胶标签,自由定制的标签
  2. Euraka-服务注册和发现原理
  3. java 字符串固定长度切割
  4. 超1000万件!高性能复合材料和金属材料挤出3D打印到底能做什么
  5. 自学前端 | 方法不对等于白学
  6. 手把手教你写第一个微信小程序页面
  7. 聊聊 Sharding-JDBC
  8. python实现单位换算计算
  9. nodejs multiparty 文件上传
  10. 第一阶段20 C语言预处理