/** * 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 适配器模式"
调用:
<!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:
{ "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