typescript: Facade Pattern
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | /** * Facade pattern 外观是一种结构型设计模式, 能为复杂系统、 程序库或框架提供一个简单 (但有限) 的接口。 * The Facade class provides a simple interface to the complex logic of one or * several subsystems. The Facade delegates the client requests to the * appropriate objects within the subsystem. The Facade is also responsible for * managing their lifecycle. All of this shields the client from the undesired * complexity of the subsystem. */ class Facade { protected subsystem1: Subsystem1; protected subsystem2: Subsystem2; /** * Depending on your application's needs, you can provide the Facade with * existing subsystem objects or force the Facade to create them on its own. */ constructor(subsystem1?: Subsystem1, subsystem2?: Subsystem2) { this .subsystem1 = subsystem1 || new Subsystem1(); this .subsystem2 = subsystem2 || new Subsystem2(); } /** * The Facade's methods are convenient shortcuts to the sophisticated * functionality of the subsystems. However, clients get only to a fraction * of a subsystem's capabilities. */ public operation(): string { let result = 'Facade initializes subsystems:\n '; result += this.subsystem1.operation1(); result += this.subsystem2.operation1(); result += ' Facade orders subsystems to perform the action:\n '; result += this.subsystem1.operationN(); result += this.subsystem2.operationZ(); return result; } public operationSub2(): string { let result = ' Facade initializes subsystems:\n '; result += this.subsystem2.operation1(); result += ' Facade orders subsystems to perform the action:\n '; result += this.subsystem2.operationZ(); return result; } } /** * The Subsystem can accept requests either from the facade or client directly. * In any case, to the Subsystem, the Facade is yet another client, and it' s not * a part of the Subsystem. */ class Subsystem1 { public operation1(): string { return 'Subsystem1: Ready!\n' ; } // ... public operationN(): string { return 'Subsystem1: Go!\n' ; } } /** * Some facades can work with multiple subsystems at the same time. */ class Subsystem2 { public operation1(): string { return 'Subsystem2: Get ready!\n' ; } // ... public operationZ(): string { return 'Subsystem2: Fire!' ; } } /** * The client code works with complex subsystems through a simple interface * provided by the Facade. When a facade manages the lifecycle of the subsystem, * the client might not even know about the existence of the subsystem. This * approach lets you keep the complexity under control. */ function clientCodeFacade(facade: Facade) { // ... let str= "" ; console.log(facade.operation()); str=facade.operation(); return str; // ... } /** * The client code may have some of the subsystem's objects already created. In * this case, it might be worthwhile to initialize the Facade with these objects * instead of letting the Facade create new instances. */ const subsystem1 = new Subsystem1(); const subsystem2 = new Subsystem2(); const facade = new Facade(subsystem1, subsystem2); //clientCodeFacade(facade); let puFac1=clientCodeFacade(facade); const facade2 = new Facade(subsystem1, subsystem2); let puFac2=facade2.operationSub2(); let messageFacade: string = 'Hello World,This is a typescript!,涂聚文 Geovin Du Web'; document.body.innerHTML = messageFacade+ ",one=" +puFac1+ ",two=" +puFac2+ ",TypeScript Facade Pattern 外观模式" |
调用:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <! doctype html> < html lang="en"> < head > < meta charset="UTF-8"> < meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> < meta http-equiv="X-UA-Compatible" content="ie=edge"> < head >< title >TypeScript:Facade Pattern 外观模式</ title > < meta name="Description" content="geovindu,涂聚文,Geovin Du"/> < meta name="Keywords" content="geovindu,涂聚文,Geovin Du"/> < meta name="author" content="geovindu,涂聚文,Geovin Du"/> </ head > < body > < script src="dist/Facadets.js"></ script > </ body > </ html > |
输出:
data structures and algorithms with object-oriented design patterns in c++
https://web.archive.org/web/20161220060802/http://www.brpreiss.com/books/opus4/
https://eduarmandov.files.wordpress.com/2017/05/c_c-data-structures-and-algorithms-in-c.pdf
http://www.uoitc.edu.iq/images/documents/informatics-institute/Competitive_exam/DataStructures.pdf
https://faculty.washington.edu/jstraub/dsa/Master_2_7a.pdf
https://cslab.pepperdine.edu/warford/cosc320/dp4ds-Chapter-01.pdf
https://cslab.pepperdine.edu/warford/cosc320/dp4ds-Chapter-02.pdf
https://cslab.pepperdine.edu/warford/cosc320/dp4ds-Chapter-04.pdf
data structures and algorithms with object-oriented design patterns in java
https://web.archive.org/web/20161130145728/http://www.brpreiss.com/books/opus5/
https://book.huihoo.com/data-structures-and-algorithms-with-object-oriented-design-patterns-in-java/html/
https://everythingcomputerscience.com/books/schoolboek-data_structures_and_algorithms_in_java.pdf
http://bedford-computing.co.uk/learning/wp-content/uploads/2016/08/Data-Structures-and-Algorithms-in-Java-6th-Edition.pdf
https://cin.ufpe.br/~grm/downloads/Data_Structures_and_Algorithms_in_Java.pdf
data structures and algorithms with object-oriented design patterns in c#
https://web.archive.org/web/20161016151655/http://www.brpreiss.com/books/opus6/
https://theswissbay.ch/pdf/Gentoomen%20Library/Programming/CSharp/O%27Reilly%20C%23%203.0%20Design%20Patterns.pdf
https://dl.ebooksworld.ir/books/Design.Patterns.in.NET.6.3rd.Edition.Dmitri.Nesteruk.Apress.9781484282441.EBooksWorld.ir.pdf
http://programming.etherealspheres.com/backup/ebooks%20-%20Other%20Programming%20Languages/Data%20Structures%20And%20Algorithms%20With%20Object-Oriented%20Design%20Patterns%20In%20C%20Sharp.pdf
data structures and algorithms with object-oriented design patterns in python
https://web.archive.org/web/20161220091736/http://www.brpreiss.com/books/opus7/
https://github.com/cjbt/Free-Algorithm-Books/blob/master/book/Data%20Structures%20%26%20Algorithms%20in%20Python.pdf
https://github.com/cjbt/Free-Algorithm-Books/
https://github.com/GauravWalia19/Free-Algorithms-Books
https://edu.anarcho-copy.org/Programming%20Languages/Python/Python%20Data%20Structures%20and%20Algorithms.pdf
https://doc.lagout.org/science/0_Computer%20Science/2_Algorithms/Data%20Structures%20and%20Algorithms%20using%20Python%20%5BNecaise%202010-12-21%5D.pdf
https://donsheehy.github.io/datastructures/fullbook.pdf
https://github.com/GauravWalia19/Free-Algorithms-Books
https://github.com/takaakit/design-pattern-examples-in-typescript
https://typescript.helpful.codes/patterns/Bridge/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
2022-10-08 CSharp: Strategy Pattern in donet core 3
2022-10-08 CSharp: Observer Pattern in donet core 3