design-patterns-in-angular icon indicating copy to clipboard operation
design-patterns-in-angular copied to clipboard

Deprecated | new project: https://github.com/Itchimonji/design-patterns-in-typescript

Design Patterns In Angular

  • Run ng serve for a dev server. Navigate to http://localhost:4201/
  • Run ng generate module singleton --route singleton --module app.module to create a feature module with routing

Creational Patterns

Abstract Factory

  • short description: create a related object family
  • applicability: system is capsulated of the creation & composition of its models
  • visual resource: https://refactoring.guru/design-patterns/abstract-factory
  • expandability: concrete factories as singletons, factory method for creation of concrete objects, for too much objects you can use the Prototype Pattern
UML

Abstract Factory

UML: example of this repo

Abstract Factory Example

Singleton

  • short description: hold one instance globally
  • visual resource: https://refactoring.guru/design-patterns/singleton
UML

Singleton

UML: example of this repo

Singleton Example

Prototype (Clone)

  • short description: clone/copy a component
  • applicability: runtime specification of objects (dynamic loading), to many different objects for factories
  • visual resource: https://refactoring.guru/design-patterns/prototype
  • expandability: implementation of prototype manager (hold all prototype instances), deep-cloinig,
UML

Prototype

UML: example of this repo

Prototype Example

Builder

  • short description: blueprint for different products with different features
  • visual resource: https://refactoring.guru/design-patterns/builder
  • expandability: abstract class or interface isn't needed for "product"-objects
UML

Builder

UML: example of this repo

Example

Factory Method (Virtual Constructor)

  • short description: provide an interface for creating objects in superclass
  • visual resource: https://refactoring.guru/design-patterns/factory-method
  • expandability: parameterized contructor for universal factory method (like abstract factory)
UML

Factory Method

UML: example of this repo

Factory Method Example

Structural Patterns

Adapter (Wrapper)

  • short description: allows objects with incompatible interfaces to collaborate
  • visual resource: https://refactoring.guru/design-patterns/adapter
  • expandability: 2-way-adapter for aptee and target (multiple inheritance)
UML

Adapter

UML: example of this repo

Adapter Example

Bridge

  • short description: separate the abstraction from the implementation
  • visual resource: https://refactoring.guru/design-patterns/bridge
UML

Bridge

UML: example of this repo

Bridge Example

Composite (Object Tree)

  • short description: compose objects into tree structures
  • visual resource: https://refactoring.guru/design-patterns/composite
UML

Composite

UML: example of this repo

Composite Example

Decorator (Wrapper)

  • short description: attach new behaviors to objects by placing these objects inside special wrapper objects that contain the behaviors
  • visual resource: https://refactoring.guru/design-patterns/decorator
UML

Decorator

UML: example of this repo

Decorator Example

Facade

  • short description: provides a simplified interface to a library
  • visual resource: https://refactoring.guru/design-patterns/facade
UML

Facade

UML: example of this repo

Facade Example

Flyweight (Cache)

  • short description: sharing common parts of state between multiple objects instead of keeping all of the data in each object
  • visual resource: https://refactoring.guru/design-patterns/flyweight
UML

Flyweight

UML: example of this repo

Flyweight Example

Proxy

  • short description: controls access to the original object
  • visual resource: https://refactoring.guru/design-patterns/proxy
UML

Proxy

UML: example of this repo

Proxy Example

Mediator

  • short description: reduce chaotic dependencies between objects; only collaboration via a mediator
  • visual resource: https://refactoring.guru/design-patterns/mediator
UML

Mediator

UML: example of this repo

Mediator Example

Iterator

  • short description: traverse elements of a collection without exposing its underlying representation
  • visual resource: https://refactoring.guru/design-patterns/iterator
UML

Iterator

UML: example of this repo

Iterator Example

Memento

  • short description: save and restore the previous state of an object without revealing the details of its implementation
  • visual resource: https://refactoring.guru/design-patterns/memento
UML

Memento

UML: example of this repo

Memento Example

Strategy

  • short description: define a family of algorithms, put each of them into a separate class, and make their objects interchangeable
  • visual resource: https://refactoring.guru/design-patterns/strategy
UML

Strategy

UML: example of this repo

Strategy Example

Command

  • short description: turns a request into a stand-alone object that contains all information about the request
  • visual resource: https://refactoring.guru/design-patterns/command
UML

Command

UML: example of this repo

Command Example

Observer

  • short description: define a subscription mechanism to notify multiple objects about any events that happen to the object they’re observing
  • visual resource: https://refactoring.guru/design-patterns/observer
UML

Observer

UML: example of this repo

Observer Example

Visitor

  • short description: separate algorithms from the objects on which they operate
  • visual resource: https://refactoring.guru/design-patterns/visitor
UML

Visitor

UML: example of this repo

Visitor Example

State

  • short description: lets an object alter its behavior when its internal state changes. It appears as if the object changed its class
  • visual resource: https://refactoring.guru/design-patterns/state
UML

State

UML: example of this repo

State Example

Template Method

  • short description: defines the skeleton of an algorithm in the superclass but lets subclasses override specific steps of the algorithm without changing its structure
  • visual resource: https://refactoring.guru/design-patterns/state
UML

Template Method

UML: example of this repo

Template Method Example

Chain Of Responsibility

  • short description: 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
  • visual resource: https://refactoring.guru/design-patterns/state
UML

Chain of Responsibility Method

UML: example of this repo

Chain of Responsibility Method Example

Resources

  • Design Patterns by GoF
  • https://refactoring.guru/
  • https://www.geeksforgeeks.org/