typescript: Adapter 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 | /** * Adapter pattern 适配器是一种结构型设计模式, 它能使不兼容的对象能够相互合作。 * file: Adapterts.ts * * */ /** * The Target defines the domain-specific interface used by the client code. */ class Target { public request(): string { return 'Target: The default target\'s behavior.' ; } } /** * The Adaptee contains some useful behavior, but its interface is incompatible * with the existing client code. The Adaptee needs some adaptation before the * client code can use it. */ class Adaptee { /** * * @returns */ public specificRequest(): string { return '.eetpadA eht fo roivaheb laicepS' ; } } /** * The Adapter makes the Adaptee's interface compatible with the Target's * interface. */ class Adapter extends Target { /** * */ private adaptee: Adaptee; /** * * @param adaptee */ constructor(adaptee: Adaptee) { super (); this .adaptee = adaptee; } /** * * @returns */ public request(): string { const result = this .adaptee.specificRequest().split( '' ).reverse().join( '' ); return `Adapter: (TRANSLATED) ${result}`; } } /** * The client code supports all classes that follow the Target interface. * @param target * @returns */ function clientCodeadapter(target: Target) { let str= "" ; console.log(target.request()); str=target.request.toString(); return str; } console.log( 'Client: I can work just fine with the Target objects:' ); const target = new Target(); clientCodeadapter(target); console.log( '' ); const adaptee = new Adaptee(); console.log( 'Client: The Adaptee class has a weird interface. See, I don\'t understand it:' ); console.log(`Adaptee: ${adaptee.specificRequest()}`); console.log( '' ); console.log( 'Client: But I can work with it via the Adapter:' ); const adapter = new Adapter(adaptee); clientCodeadapter(adapter); let strada=clientCodeadapter(adapter); let strada1= "geovindu" ; let messageada: string = 'Hello World,This is a typescript!,涂聚文 Geovin Du Web' ; document.body.innerHTML = messageada+ "," +strada+ "," +strada1+ ",TypeScript 适配器模式" |
调用:
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:适配器模式</ 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/Adapterts.js"></ script > </ body > </ html > |
输出:
tsconfig.json:
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 | { "compilerOptions" : { "target" : "ES6" , //"target": "es5", "skipLibCheck" : true , "module" : "CommonJS" , //CommonJS //esnext "outDir" : "./dist" , "rootDir" : "./src" , "esModuleInterop" : true , "resolveJsonModule" : true , "composite" : true , // required on the dependency project for references to work https://github.com/microsoft/TypeScript/issues/30693 "sourceMap" : true , //true //false "moduleResolution" : "node" , "allowSyntheticDefaultImports" : true , //"strict": true, //"strictPropertyInitialization": false /*"emitDecoratorMetadata": false, "experimentalDecorators": true, "removeComments": false, "strict": true, "strictNullChecks": true,*/ //"declaration": false /* "strict": true, "experimentalDecorators": true, "useDefineForClassFields": false, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "esModuleInterop": true, "moduleResolution": "node", // Tells TypeScript to read JS files, as normally they are ignored as source files "allowJs": true, // Generate d.ts files "declaration": true, // go to js file when using IDE functions like "Go to Definition" in VSCode "declarationMap": true, // This compiler run should only output d.ts files "emitDeclarationOnly": true "lib": [ "es2017", "es2018" ]*/ }, "includes" : [ "src/**/*.ts" , "other-src/**/*.ts" ], "exclude" :[ "rollup.config.js" , "test" , "dist" , "node_modules" , ], } |
npm init -y
npm install -g typescript
tsc --version
npm install -g ts-node
npm install eslint --save-dev
npm install typescript typescript-eslint-parser --save-dev
npm install eslint-plugin-typescript --save-dev
npm install --save-dev ts-loader
npm install --save-dev typescript ts-loader
npm install --save-dev webpack webpack-cli
npm install webpack
npm i -D webpack webpack-cli webpack-dev-server
npm install webpack webpack-cli typescript ts-loader --save-dev
npm i -D @babel/core @babel/preset-env babel-loader core-js
npm i -D less less-loader css-loader style-loader
npm i -D postcss postcss-loader postcss-preset-env
https://www.typescriptlang.org/docs/handbook/2/modules.html
https://www.typescriptlang.org/tsconfig#module
data structures and problem solving using java 4th edition
https://cscnt.savannahstate.edu/StudentFiles/Data_Structure/Data-Structures-Problem-Solving-Using-Java.pdf
http://computo.fismat.umich.mx/~htejeda/books/data/Data_Structures_and_Problem_Solving_Using_Java__4ed__Weiss.pdf
https://users.cis.fiu.edu/~weiss/dsj4/code/
https://users.cis.fiu.edu/~weiss/dsj3/code/
http://users.cs.fiu.edu/~weiss/dsj2/
http://users.cs.fiu.edu/~weiss/dsj2/code/code.html
http://users.cs.fiu.edu/~weiss/dsj/code/
https://users.cis.fiu.edu/~weiss/
https://users.cis.fiu.edu/~weiss/cs/
https://users.cis.fiu.edu/~weiss/dsaa_c++4/code/
data structures and algorithms using java
https://cin.ufpe.br/~grm/downloads/Data_Structures_and_Algorithms_in_Java.pdf
https://github.com/shshankar1/ebooks/blob/master/Data%20Structures%20and%20Algorithms%20in%20Java%2C%206th%20Edition.pdf
http://bedford-computing.co.uk/learning/wp-content/uploads/2016/08/Data-Structures-and-Algorithms-in-Java-6th-Edition.pdf
https://everythingcomputerscience.com/books/schoolboek-data_structures_and_algorithms_in_java.pdf
data structures and algorithms using c++
http://www.uoitc.edu.iq/images/documents/informatics-institute/Competitive_exam/DataStructures.pdf
https://eduarmandov.files.wordpress.com/2017/05/c_c-data-structures-and-algorithms-in-c.pdf
https://github.com/GunterMueller/Books-3/blob/master/Data%20Structure%20and%20Algorithm%20Analysis%20in%20C%2B%2B%204th%20ed.pdf
https://people.cs.vt.edu/shaffer/Book/C++3e20100119.pdf
https://github.com/GunterMueller/Books-3
https://github.com/GunterMueller/Books
https://github.com/GunterMueller/Books-2
https://bu.edu.eg/portal/uploads/Computers%20and%20Informatics/Computer%20Science/1266/crs-10600/Files/Esam%20Halim%20Houssein%20Abd%20El-Halim_4-%20Data-Structure%20Using%20C++%20Malik.pdf
https://people.computing.clemson.edu/~goddard/texts/dataStructCPP/fullText.pdf
https://repository.dinus.ac.id/docs/ajar/Principles_of_Data_Structures_Using_C_and_C++.pdf
https://dl.ebooksworld.ir/books/Introduction.to.Algorithms.4th.Leiserson.Stein.Rivest.Cormen.MIT.Press.9780262046305.EBooksWorld.ir.pdf
https://o6ucs.files.wordpress.com/2012/10/data-structures-algorithms-and-applications-in-c-by-sartraj-sahani.pdf
https://github.com/GauravWalia19/Free-Algorithms-Books
谷歌浏览器查看:
https://www.cet.edu.in/noticefiles/280_DS%20Complete.pdf
https://aa.bbs.tr/lab/cen215-data-structures/Data-Structures-Using-C-2nd-edition.pdf
https://mrajacse.files.wordpress.com/2012/08/data-structures-and-algorithm-analysis-in-c-mark-allen-weiss.pdf
https://csit.ust.edu.sd/files/2019/10/Data-structure-using-C-1.pdf
https://www.cs.bham.ac.uk/~jxb/DSA/dsa.pdf
https://theswissbay.ch/pdf/Gentoomen%20Library/Algorithms/Algorithms%20in%20C.pdf
https://www.mta.ca/~rrosebru/oldcourse/263114/Dsa.pdf
https://mu.ac.in/wp-content/uploads/2021/05/Data-Structure-Final-.pdf
https://opendatastructures.org/versions/edition-0.1e/ods-cpp.pdf
http://library.bagrintsev.me/CPP/Malik%20-%20Data%20Structures%20Using%20C%2B%2B%20-%202010.pdf
http://www.iimchyderabad.com/Material/DSCpp.pdf
https://tfetimes.com/wp-content/uploads/2015/04/C-3e20120102.pdf
https://quincycollege.edu/wp-content/uploads/Anderson-and-Krathwohl_Revised-Blooms-Taxonomy.pdf
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
2022-10-06 CSharp: Composite Pattern in donet core 3
2022-10-06 CSharp: Flyweight Pattern in donet core 3
2022-10-06 Python: Factory Method Pattern