/design-pattern-for-ts

design pattern for typescript

Primary LanguageTypeScript

design-pattern-for-ts

design pattern for typescript

创造类

main

Ensure a class has only one instance, and provide a global point of access to it.(确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例。)

创造类

main

Define an interface for creating an object, bug let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses (定义一个用于创建对象的接口,让子类决定实例化哪一个类。工厂方法使一个类的实例化延迟到其子类。)

创造类

main

Provide an interface for creating families of related of dependent objects without specifying their concrete classes. (为创建一组相关或相互依赖的对象提供一个接口,而且无需指定它们的具体类)

行为类

main

Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.(定义一个操作中的算法的结构,而将一些步骤延迟到子类中。使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤。)

创造类

main

Separate the construction of a complex object from its representation so that the same construction process can create different representations.(将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。)

结构类

main

Provide a surrogate or placeholder for another object to control access to it. (为其他对象提供一种代理以控制对这个对象的访问)

创造类

main

Specify the kinds of objects to create using a prototypical instance,and create new objects by coping this prototype. (用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象。)

行为类

image-5

Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it let's you vary their interaction independently. (用一个中介对象封装一系列的对象交互,中介者使各对象不需要显式地相互作用,从而使其耦合松散,而且可以独立地改变他们之间的交互。)

graph LR
    A[test] --> B{test2}
    B -- Yes --> C[test3]
    B -- No --> D[test4]
    D --> A
Loading