Skip to content

Commit 52d3a59

Browse files
added docs
1 parent bad9e2b commit 52d3a59

File tree

27 files changed

+161
-3
lines changed

27 files changed

+161
-3
lines changed

README.md

+46
Original file line numberDiff line numberDiff line change
@@ -1 +1,47 @@
11
# Desing Patterns in Typescript
2+
3+
All the 23 GoF patterns implemented in Typescript.
4+
5+
## Building and running
6+
7+
### `npm run build`
8+
9+
Builds the project
10+
11+
### `npm start`
12+
13+
Runs the project
14+
15+
## Patterns
16+
17+
### Creational Patterns
18+
19+
* [Abstract Factory](creational/abstract-factory/README.md)
20+
* [Builder](creational/builder/README.md)
21+
* [Factory Method](creational/factory-method/README.md)
22+
* [Prototype](creational/prototype/README.md)
23+
* [Singleton](creational/singleton/README.md)
24+
25+
### Structural Patterns
26+
27+
* [Adapter](structural/adapter/README.md)
28+
* [Bridge](structural/bridge/README.md)
29+
* [Composite](structural/composite/README.md)
30+
* [Decorator](structural/decorator/README.md)
31+
* [Facade](structural/facade/README.md)
32+
* [Flyweight](structural/flyweight/README.md)
33+
* [Proxy](structural/proxy/README.md)
34+
35+
### Behavioral Patterns
36+
37+
* [Chain of Responsibility](behavioral/chain-of-responsibility/README.md)
38+
* [Command](behavioral/command/README.md)
39+
* [Interpreter](behavioral/interpreter/README.md)
40+
* [Iterator](behavioral/iterator/README.md)
41+
* [Mediator](behavioral/mediator/README.md)
42+
* [Memento](behavioral/memento/README.md)
43+
* [Observer](behavioral/observer/README.md)
44+
* [State](behavioral/state/README.md)
45+
* [Strategy](behavioral/strategy/README.md)
46+
* [Template Method](cbehavioraltemplate-method/README.md)
47+
* [Visitor](behavioral/visitor/README.md)

behavioral/README.md

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Chain of Responsibility Pattern
2+
3+
Chain of Responsibility is a behavioral design pattern that lets you pass requests along a chain of handlers. Upon receiving a request, each handler decides either to process the request or to pass it to the next handler in the chain. [source](https://refactoring.guru/design-patterns/chain-of-responsibility)
4+
5+
In this example [SaleHandler](Chain.ts) defines a chain of responsibility.

behavioral/command/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Command Pattern
2+
3+
Command is a behavioral design pattern that turns a request into a stand-alone object that contains all information about the request. This transformation lets you parameterize methods with different requests, delay or queue a request’s execution, and support undoable operations. [source](https://refactoring.guru/design-patterns/command)
4+
5+
In this example [Remote](Remote.ts) uses [Command](Commands.ts) to communicate with [Television](Television.ts).

behavioral/interpreter/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Interpreter Pattern
2+
3+
The interpreter pattern is a design pattern that specifies how to evaluate sentences in a language. [source](https://en.wikipedia.org/wiki/Interpreter_pattern)
4+
5+
In this example [Expression](Interpreters.ts) is used to evaluate mathematical operations in string form.

behavioral/iterator/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Iterator Pattern
2+
3+
Iterator is a behavioral design pattern that lets you traverse elements of a collection without exposing its underlying representation (list, stack, tree, etc.). [source](https://refactoring.guru/design-patterns/iterator)
4+
5+
In this example [UserIterator](Iterators.ts) is used to iterate [UserCollection](Users.ts).

behavioral/mediator/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Mediator Pattern
2+
3+
Mediator is a behavioral design pattern that lets you reduce chaotic dependencies between objects. The pattern restricts direct communications between the objects and forces them to collaborate only via a mediator object. [source](https://refactoring.guru/design-patterns/mediator)
4+
5+
In this example [AirTrafficControlMediator](Mediators.ts) is used to coordinate different istances of [Plane](Planes.ts).

behavioral/memento/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Memento Pattern
2+
3+
Memento is a behavioral design pattern that lets you save and restore the previous state of an object without revealing the details of its implementation. [source](https://refactoring.guru/design-patterns/memento)
4+
5+
In this example [History](History.ts) holds a collection of [Snapshot](Mementos.ts) to restore previous states of [Editor](Editor.ts).

behavioral/observer/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Observer Pattern
2+
3+
Observer is a behavioral design pattern that lets you define a subscription mechanism to notify multiple objects about any events that happen to the object they’re observing. [source](https://refactoring.guru/design-patterns/observer)
4+
5+
In this example [Radiostation](RadioStation.ts) notifies multiple instances of [RadioListener](Subscribers.ts) when broadcasting.

behavioral/state/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# State Pattern
2+
3+
State is a behavioral design pattern that lets an object alter its behavior when its internal state changes. It appears as if the object changed its class. [source](https://refactoring.guru/design-patterns/state)
4+
5+
In this example [CarState](States.ts) holds the state of [Car](Car.ts).

behavioral/strategy/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Strategy Pattern
2+
3+
Strategy is a behavioral design pattern that lets you define a family of algorithms, put each of them into a separate class, and make their objects interchangeable. [source](https://refactoring.guru/design-patterns/strategy)
4+
5+
In this example [Sorter](Sorter.ts) allows different types of [SortingStrategy](Strategies.ts).

behavioral/template-method/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Template Method Pattern
2+
3+
Template Method is a behavioral design pattern that defines the skeleton of an algorithm in the superclass but lets subclasses override specific steps of the algorithm without changing its structure. [source](https://refactoring.guru/design-patterns/template-method)
4+
5+
In this example [LoggerTemplate](Templates.ts) implements the template method patters.

behavioral/visitor/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Visitor Pattern
2+
3+
Visitor is a behavioral design pattern that lets you separate algorithms from the objects on which they operate. [source](https://refactoring.guru/design-patterns/visitor)
4+
5+
In this example [ShapeVistor](Visitors.ts) is a visitor of [Shape](Shapes.ts).

creational/README.md

-1
This file was deleted.

creational/abstract-factory/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Abstract Factory Pattern
2+
3+
Abstract Factory is a creational design pattern that lets you produce families of related objects without specifying their concrete classes. [source](https://refactoring.guru/design-patterns/abstract-factory)
4+
5+
In this example [RigFactory](Factories.ts) will bundle together a [Case](Cases.ts) and a [Monitor](Monitors.ts) to produce a computer rig.

creational/builder/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Builder Pattern
2+
3+
Builder is a creational design pattern that lets you construct complex objects step by step. The pattern allows you to produce different types and representations of an object using the same construction code. [source](https://refactoring.guru/design-patterns/builder)
4+
5+
In this example [Director](Director.ts) will instruct [SandwichBuilder](Builders.ts) to make different sizes of sandwich.

creational/factory-method/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Factory Method Pattern
2+
3+
Factory Method is a creational design pattern that provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created. [source](https://refactoring.guru/design-patterns/factory-method)
4+
5+
In this example [VehicleFactory](Factories.ts) will create different types of [Vehicle](Vehicles.ts).

creational/prototype/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Prototype Pattern
2+
3+
Prototype is a creational design pattern that lets you copy existing objects without making your code dependent on their classes. [source](https://refactoring.guru/design-patterns/prototype)
4+
5+
In this example [Prototype](Prototype.ts) allows [Rectangle](Prototype.ts) to be cloned.

creational/singleton/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Singleton Pattern
2+
3+
Singleton is a creational design pattern that lets you ensure that a class has only one instance, while providing a global access point to this instance. [source](https://refactoring.guru/design-patterns/singleton)
4+
5+
In this example [Singleton](Singletons.ts) implements the singleton pattern.

structural/README.md

-1
This file was deleted.

structural/adapter/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Adapter Pattern
2+
3+
Adapter is a structural design pattern that allows objects with incompatible interfaces to collaborate. [source](https://refactoring.guru/design-patterns/adapter)
4+
5+
In this example [LinuxAdapter](Adapter.ts) allows [Windows](Windows.ts) programs to run on [Linux](Linux.ts).

structural/bridge/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Bridge Pattern
2+
3+
Bridge is a structural design pattern that lets you split a large class or a set of closely related classes into two separate hierarchies (abstraction and implementation) which can be developed independently of each other. [source](https://refactoring.guru/design-patterns/bridge)
4+
5+
In this example [House](Houses.ts) is the abstraction, and [Garden](Gardens.ts) the implementation.

structural/composite/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Composite Pattern
2+
3+
Composite is a structural design pattern that lets you compose objects into tree structures and then work with these structures as if they were individual objects. [source](https://refactoring.guru/design-patterns/composite)
4+
5+
In this example [Division](Army.ts) implements the composite pattern.

structural/decorator/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Decorator Pattern
2+
3+
Decorator is a structural design pattern that lets you attach new behaviors to objects by placing these objects inside special wrapper objects that contain the behaviors. [source](https://refactoring.guru/design-patterns/decorator)
4+
5+
In this example [BaseDecorator](Decorators.ts) decorates [Person](Person.ts) with clothing.

structural/facade/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Facade Pattern
2+
3+
Facade is a structural design pattern that provides a simplified interface to a library, a framework, or any other complex set of classes. [source](https://refactoring.guru/design-patterns/facade)
4+
5+
In this example [FormulaFacade](Decorators.ts) provides a simpler interface to [Formulas.ts](Person.ts).

structural/flyweight/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Flyweight Pattern
2+
3+
Flyweight is a structural design pattern that lets you fit more objects into the available amount of RAM by sharing common parts of state between multiple objects instead of keeping all of the data in each object. [source](https://refactoring.guru/design-patterns/flyweight)
4+
5+
In this example [CloudType](Flyweight.ts) shares the color attribute of [Cloud](Flyweight.ts).

structural/proxy/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Proxy Pattern
2+
3+
Proxy is a structural design pattern that lets you provide a substitute or placeholder for another object. A proxy controls access to the original object, allowing you to perform something either before or after the request gets through to the original object. [source](https://refactoring.guru/design-patterns/proxy)
4+
5+
In this example [WireTransferProxy](Proxy.ts) is a proxy of [WireTransfer](Proxy.ts) and does not allow uncovered transfers.

0 commit comments

Comments
 (0)