Skip to content

Latest commit

 

History

History
47 lines (33 loc) · 1.42 KB

README.md

File metadata and controls

47 lines (33 loc) · 1.42 KB

DesginPatterns

Table Of Contents

Behavioral :

Observer Pattern

  • One object notifies other objects about its state change.
  • It is a one-to-many relationship.
  • When the state of one object changes, other object which are subscribed to it gets notified about the state change.
  • Observable protocol has three abstract methods :
    • add(observerX) : to add an observer.
    • remove(observerX) : to remove a specific observer.
    • notify() : to notify all observers.

Code example here

Implementation

Demo

Strcutural :

Adapter Pattern

  • Named also Wrapper.
  • Allows objects with incompatible interfaces to collaborate.
  • lets you create a middle-layer class that serves as a translator between your code and a legacy class, a 3rd-party class or any other class with a weird interface.
  • Do not add an additional behavior.

Code example here

Implementation

Demo