Skip to content

Latest commit

 

History

History
71 lines (68 loc) · 3.67 KB

File metadata and controls

71 lines (68 loc) · 3.67 KB

Design Patterns in JavaScript

List of content

  • SOLID Design Principles

  • Design Principles:

    • Builder
      • Separate component for when object construction gets too complicated.
      • Can create mutually cooperating sub-builders.
      • Often has a fluent interface.
    • Factory
      • Factory method more expressive than constructor.
      • A separate class with factory methods is a Factory.
      • Class hierarchies can have corresponding hierarchies of factories (Abstract Factory).
    • Prototype
      • Creation of object from an existing object.
      • Requires either explicit deep copy or copy through serialization.
      • Additional work required to preserve type.
    • Singleton
      • When you need to ensure just a single instance exists.
      • Can return same object from constructor on every call.
      • Direct dependence on a Singleton is dangerous.
    • Adapter
      • Converts the interface you get to the interface you need.
    • Bridge
      • Decouple abstraction from implementation.
    • Composite
      • Allows clients to treat individual objects and composition of objects uniformly.
    • Decorator
      • Attach additional responsabilities to objects without modifiying those object or inheriting from them.
      • Decorators are composable with each other.
    • Façade
      • Provide a single unified interface over a set of system/interfaces.
    • Flyweight
      • Memory saving technique
      • Efficiently support very large numbers of similar objects.
    • Proxy
      • Provide a surrogate object that forwards calls to the real object whilte performing additional fucntions.
      • Access control, communication, logging, etc.
    • Chain of Responsability
      • Allow components to process information/events in a chain.
      • Each element in the chain refers to next element.
      • Make a list and go through it.
    • Command
      • Encapsulate a request into a separate object.
      • Good for audit, replay, undo/redo.
      • Part of CQS/CQRS
    • Interpreter
      • Transform textual input into object-oriented structures.
      • Used by interpreters, compilers, static analysis tools, etc.
      • Compiler theory is a separate branch of Computer Science.
    • Iterator
      • Provides an interface for accessing elements of an aggregate object.
      • Object can be made iterable (for loop).
    • Mediator
      • Provides mediation servies between two objects.
    • Memento
      • Yields tokens representing system states.
      • Tokens do not allow direct manipulation, but can be used in appropriate APIs.
    • Observer
      • Allows notifications of changes/happening in a component.
    • State
      • We model system by having one of a possible states and transitions between these states.
      • Such a system is called a state machine.
      • Special frameworks exists to orchestrate state machines.
    • Strategy and Template method
      • Both define a skeleton algorithm with details filled in by implementor.
      • Strategy uses ordinary composition, template method uses inheritance.
    • Visitor
      • Allows non-intrusive addition of functionality tho hierarchies.