Skip to content

oro8oro/nomnoml-design-patterns

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 

Repository files navigation

Nomnoml Design Patterns

In this project we present the well-known OOP design patterns from the GoF Book in Nomnoml

For the Javascript implementation see: js-design-patterns

Images were generated by Nomnoml from the sources. The sequence diagrams were generated by JS Sequence Diagrams.

Everyone is welcome to improve on this and provide implementation in various programming languages.

Creational Patterns

Abstract Factory

Abstract Factory

[<abstract>AbstractFactory
	|
	| +createProductA()
	 +createProductB()
]

[AbstractFactory]<:-[ConcreteFactory1
	|
	| +createProductA()
	 +createProductB()
]

[AbstractFactory]<:-[ConcreteFactory2
	|
	| +createProductA()
	 +createProductB()
]

[AbstractFactory]<-[Client
	(from design_patterns)
	|
	| 
]

[Client]->[<abstract>AbstractProductA
	|
	| 
]

[AbstractProductA]<:-[ProductA1
	|
	|

]

[AbstractProductA]<:-[ProductA2
	|
	|

]

[<abstract>AbstractProductB
	|
	| 
]

[AbstractProductB]<:-[ProductB1
	|
	|

]

[AbstractProductB]<:-[ProductB2
	|
	|

]

[ConcreteFactory1]-->[ProductA1]
[ConcreteFactory1]-->[ProductB1]
[ConcreteFactory2]-->[ProductA2]
[ConcreteFactory2]-->[ProductB2]

Builder

Builder

[Builder
	|
    |+buildPart()
]

[Director |
	+builder: Builder
    |+construct()
    +new Director()
]o-[Builder]

[Director]--[<note>this.builder.buildPart();]
[Builder]<:-[ConcreteBuilder
	|
    |+buildPart()
    +getResult():Product
    +new ConcreteBuilder()
    +buildPartA()
    +buildPartB()
    +buildPartC()
]

[ConcreteBuilder]--><<create>>[Product]

Builder

participant Client
participant Director
Client-->ConcreteBuilder:<<create>>\nnew ConcreteBuilder
Client-->Director:<<create>>\nnew Director(ConcreteBuilder)
Client->Director:construct()
Director->ConcreteBuilder:buldPartA()
Director->ConcreteBuilder:buldPartA()
Director->ConcreteBuilder:buldPartA()
Client->ConcreteBuilder:getResult()

Factory Method

Factory Method

[<abstract>Creator | |+FactoryMethod()
	+AnOperation()
]
[<abstract>Product ||]<:-[ConcreteProduct||]
[Creator]<:-[ConcreteCreator||+FactoryMethod()]
[ConcreteCreator]-->[ConcreteProduct]
[Creator]--[<note>product= FactoryMethod()]
[ConcreteCreator]--[<note>return new ConcreteProduct]

Prototype

Prototype

[Client 
	|
	|+Operation()
]--[<note>p = prototype->Clone()]

[Client]->+prototype[<abstract>Prototype||+Clone()]
[Prototype]<:-[ConcretePrototype1 ||+Clone()]
[ConcretePrototype1]--[<note>return copy of self]
[Prototype]<:-[ConcretePrototype2 ||+Clone()]
[ConcretePrototype2]--[<note>return copy of self]

Singleton

Singleton

[Singleton
  	|+static uniqueInstance
    +singletonData
    |static Instance()
    +SingletonOperation()
    +GetSingletonData()
] -- [<note>return uniqueInstance]

Structural Patterns

Adapter

Adapter MultiInheritance

[Client
	(from design_patterns)
    |
    |
]->[Target ||+Request()]

[Target]<:-[Adapter ||+Request()]
[Adapter]-:>[Adaptee ||+SpecificRequest()]
[Adapter]--[<note>SpecificRequest()]

Bridge

Bridge


[Client
	(from design_patterns)
    |
    |
]->[<abstract>Abstraction ||+Operation()]

[Abstraction]<:-[RefinedAbstraction ||]

[Abstraction]--[<note>imp->OperationImp()]
[Abstraction]o- +imp[Implementor ||+OperationImp()]
[Implementor]<:-[ConcreteImplementorA ||+OperationImp()]
[Implementor]<:-[ConcreteImplementorB ||+OperationImp()]

Composite

Composite


[Client
	(from design_patterns)
    |
    |
]->[<abstract>Component
	|
    |+Operation()
    +Add(Component)
    +Remove(Component)
    +GetChild(int)
]

[Component]<:-[Leaf||+Operation()]
[Component]<:-[Composite|
	|+Operation()
    +Add(Component)
    +Remove(Component)
    +GetChild(int)
]
[Composite]<:-[RefinedAbstraction ||]
[Composite]o- +children[Component]
[Composite]--[<note>forall g in children
g.Operation()]

Decorator

Decorator Decorator

[<abstract>Component||  operation()]
  [Client] depends --> [Component]
  [Decorator|- next: Component]
  [Decorator] decorates -- [ConcreteComponent]
  [Component] <:- [Decorator]
  [Component] <:- [ConcreteComponent]

Façade

Façade

[<package>Subsystem Classes |
	
    [Class1]
    [Class2]
    [Class3]
    [Class4]
    [Class5]
    [Class6]
    [Class7]
]

[<abstract>Facade
	|
	| 
]

[Class2]-->[Class1]
[Facade]->[Class2]
[Facade]->[Class3]
[Facade]->[Class4]
[Facade]->[Class6]
[Facade]->[Class7]

[Class5]<:-[Class6]
[Class5]<:-[Class7]
[Class1]<:-[Class3]

Flyweight

Flyweight

[FlyweightFactory |
	|+GetFlyweight(key)
]--[<note>if (flyweight.key exists) {
	return existing flyweight
    } else {
    	create new flyweight
        add it to pool of flyweights
        return the new flyweight
    }
]

[FlyweightFactory]o- +flyweights [<abstract> Flyweight ||+Operation(extrinsicState)]

[Flyweight]<:-[ConcreteFlyweight]

[FlyweightFactory]<-[Client
(from design_paterns) |
	|
]

[Client]->[ConcreteFlyweight|+instrinsicState|+Operation(extrinsicState)]
[Client]->[UnsharedConcreteFlyweight|+allState|+Operation(extrinsicState)]

Proxy

Proxy

[Client
	(from design_patterns)
    |
    |
]->[<abstract>Subject
	|
    |+Request()
]

[Subject]<:-[RealSubject ||+Request()]
[Subject]<:-[Proxy ||+Request()]

[Proxy]-->[RealSubject]
[Proxy]--[<note>realSubject->Request()]

Behavioral Patterns

Chain of Responsibility

Chain of Responsibility

[Client
	(from design_patterns)
    |
    |
]->[<abstract>Handler
	|
    |+HandleRequest()
]

[Handler]<:-[ConcreteHandler1||+HandleRequest()]
[Handler]<:-[ConcreteHandler2||+HandleRequest()]

[Handler]-> +successor [Handler]

Command

Command

[Client
	(from design_patterns)
    |
    |
]->[<abstract>Receiver
	|
    |+Action()
]

[Receiver]<- +receiver [ConcreteCommand |+state|+Execute()]
[Invoker ||+StoreCommand()]o-[Command ||+Execute()]
[Command]<:-[ConcreteCommand]

[ConcreteCommand]--[<note>receiver->Action()]
[Client]-->[ConcreteCommand]

Command Sequence

participant Receiver
participant Client
participant ConcreteCommand
participant Invoker
Client-->ConcreteCommand: <<create>>\nnew Command(Receiver)
Client->Invoker: StoreCommand(Command)
Invoker->ConcreteCommand: Execute()
ConcreteCommand->Receiver: Action()

Interpreter

Interpreter


[Client
	(from design_patterns)
    |
    |
]->[<abstract>AbstractExpression
	|
    |+Interpret(Context)
]

[Client]->[Context]

[AbstractExpression]<:-[TerminalExpression ||+Interpret(Context)]
[AbstractExpression]<:-[NonterminalExpression ||+Interpret(Context)]
[AbstractExpression]-o[NonterminalExpression]

Iterator

Iterator


[Client
	(from desing_patterns)|
    |
]->[Agregate]
[Client]->[<abstract>Iterator |
	|+First()
    +Next()
    +IsDone()
    +CurrentItem()
]

[Iterator]<:-[ConcreteIterator]
[ConcreteAgregate]--[<note>return new ConcreteIterator(this)]
[ConcreteAgregate]-->[ConcreteIterator]
[<abstract>Agregate |
	|+CreateIterator()
]<:-[ConcreteAgregate |
	|+CreateIterator()
]

[ConcreteAgregate]<-[ConcreteIterator||]


Mediator

Mediator

[<abstract>Mediator||]<:-[ConcreteMediator||]
[ConcreteMediator]->[ConcreteColleague1]
[ConcreteMediator]->[ConcreteColleague2]
[Mediator]<- +mediator[<abstract>Colleague]
[Colleague]<:-[ConcreteColleague1]
[Colleague]<:-[ConcreteColleague2]

Memento

Memento

[Originator |
	+state
    |+SetMemento(Mememnto m)
    +CreateMemento()
]

[Originator]--[<note>return newMemento(state)]
[Originator]--[<note>state = m->GetState()]

[Originator]-->[Memento |+state
	|+GetState()
    +SetState()
]

[Memento]-o +memento [Caretaker]

Memento

Caretaker->Originator: CreateMemento()
Originator-->Memento: <<create>>\n new Memento
Originator->Memento: SetState()
Caretaker->Originator: SetMemento(Memento m)
Originator->Memento: GetState()

Observer

Observer


[<abstract>Subject |
	|+Attach(Observer)
    +Detach(Observer)
    +Notify()
]<:-[ConcreteSubject 
	|+subjectState
	|+GetState()
    +SetState()
]

[Subject]--[<note>for all o in observers {o->Update()}]
[ConcreteSubject]--[<note>return subjectSate]

[Subject]-o +observers [<abstract>Observer||+Update()]
[Observer]<:-[ConcreteObserver|+observerState|+Update()]

[ConcreteSubject]<- +subject [ConcreteObserver]
[ConcreteObserver]--[<note>observerState = subject->GetState()]

Observer Sequence

participant ConcreteSubject
participant ConcreteObserver1
participant ConcreteObserver2
ConcreteObserver1->ConcreteSubject: SetState()
ConcreteSubject->ConcreteSubject: Notify()
ConcreteSubject->ConcreteObserver1: Update()
ConcreteObserver1->ConcreteSubject: GetState()
ConcreteSubject->ConcreteObserver2: Update()
ConcreteObserver2->ConcreteSubject: GetState()

State

State


[Context |
	|+Request()
]--[<note>state->Handle()]

[Context]o- +state [<abstract> State | |+Handle()]

[State]<:-[ConcreteStateA||+Handle()]
[State]<:-[ConcreteStateB||+Handle()]

Strategy

Strategy Strategy

  [Client] o- [<abstract>Strategy|  Operation()]
  [Strategy] <:-- [StrategyA]
  [Strategy] <:-- [StrategyB]

Template Method

Template Method


[<abstract>AbstractClass|
	|+TemplateMethod()
    +PrimitiveOperation1()
    +PrimitiveOperation2()
]<:-[ConcreteClass||+PrimitiveOperation1()
    +PrimitiveOperation2()
]

[AbstractClass]--[<note>...
	PrimitiveOperation1()
	...
    PrimitiveOperation2()
    ...
]

Visitor

Visitor


[Client
	(from design_patterns)
    |
    |
]->[<abstract>Visitor
	|
    |+VisitConcreteElementA(ConcretElementA)
    +VisitConcreteElementB(ConcretElementB)
]

[Visitor]<:-[ConcreteVisitor1 |
	|+VisitConcreteElementA(ConcretElementA)
    +VisitConcreteElementB(ConcretElementB)
]

[Visitor]<:-[ConcreteVisitor2 |
	|+VisitConcreteElementA(ConcretElementA)
    +VisitConcreteElementB(ConcretElementB)
]

[Client]->[ObjectStructure||]
[ObjectStructure]->[Element ||]

[Element]<:-[ConcreteElementA ||+Accept(Visitor v)
	+OperationA()
]
[ConcreteElementA]--[<note>v->VisitConcreteElementA(this)]
[Element]<:-[ConcreteElementB ||+Accept(Visitor v)
	+OperationB()
]
[ConcreteElementB]--[<note>v->VisitConcreteElementB(this)]

Visitor

ObjectStructure->ConcreteElementA: Accept(Visitor v)
participant ConcreteElementB
ConcreteElementA->ConcreteVisitor1: VisitConcreteElementA(ConcretElementA)
ConcreteVisitor1->ConcreteElementA: OperationA()
ObjectStructure->ConcreteElementB: Accept(Visitor v)
ConcreteElementB->ConcreteVisitor1: VisitConcreteElementA(ConcretElementA)
ConcreteVisitor1->ConcreteElementB: OperationA()

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published