Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

preface

Design pattern is always involved in the software development process is a part of the knowledge, is a programmer essential knowledge point. Prepare to use Type Script to consolidate typescript and learn design patterns.

The emergence of a certain technology has its purpose or design concept. When learning, you can ask yourself several questions first:

What is TypeScript?

2. What problems does TypeScript solve and what are its advantages

3. What problems are design patterns designed to solve

TypeScript

  • Is a superset of JavaScript, is a feature extension of JavaScript language
  • It can be compiled to pure JavaScript, and the compiled JavaScript can run on any browser
  • Supports ES6 standards
  • TypeScript makes applications easy to maintain, iterative, and stable
  • Advantages: Static type detection, can avoid some low-level javascript errors, making more reliable

TypeScript: Hello!

Configure the TypeScript environment

NPM i-g typescript // After installing the typescript, check whether the installation is successful by viewing the version number of tSC-VCopy the code

Create a TypeScript project

Use the command TSC –init in the project file to quickly create a tsconfig.json file or manually

Create a new hello.ts file

function say(name: string) { console.log(name); } say('Hello, nan Lu ');Copy the code

Run the project

1. The TSC (TypeScript Compiler) command translates.ts files into.js files, but this way TSC ignores the tsconfig.json configuration in the current application path, so we need to explicitly set the following parameters. Let TSC detect and translate TypeScript code in strict mode

tsc hello.ts --strict --alwaysStrict false
Copy the code

2. Another way to write code is to run the TypeScript TS-Node command line directly (essentially automatically translate first, then run)

// Support directly running TypeScript code NPM i-g ts-node using TS-NodeCopy the code
ts-node hello.ts
Copy the code

Problems arise:

Error: Cannot find module ‘typescript’ Error: Cannot find module ‘typescript’ Error: Cannot find module ‘typescript’ Error: Cannot find module ‘typescript’ Error: Cannot find module ‘typescript’ Error: Cannot find module ‘typescript’ Error: Cannot find module ‘typescript

Solution: Uninstall the current version and reinstall 3.9.*

Design patterns

  • Design pattern, a template for similar design, a design experience
  • Each design pattern has its name, applicable scenario, solution, and effect achieved
  • A solution to improve code reusability, maintainability, readability, robustness, and security.

There are 23 design patterns in total, and the existing design patterns are classified as follows:

  • Creation pattern

    • Singleton, Factory Method, Abstract Factory, Prototype, Builder
  • Structural mode

    • Adapter pattern, Bridge pattern, Decorator pattern, Composite pattern, Facade pattern, Share pattern, Proxy
  • Behavioral pattern

    • Template method pattern, command pattern, Visitor pattern, iterator pattern, Observer pattern, Mediator pattern, memo pattern, interpreter pattern, state pattern, Policy pattern, chain of Responsibility pattern

The resources

  • Loredanacirstea. Making. IO/es6 – design -…
  • Github.com/FantZero/De…

\