GoFのデザインパターン23種類をPlantUMLで表現する

ここで取り扱うUMLについては、下記Webサイトにコードを貼り付けることで図としてUMLを取得することができます。
http://www.plantuml.com/plantuml/uml/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000

#Iterator
@startuml
class Aggregate <<interface>>{
iterator()
}

Class Iterator<<interface>>{
hasNext()
next()
}

class ConcreteAggregate {
iterator()
}

Class ConcreteIterator{
aggregate
hasNext()
next()
}

ConcreteAggregate --> Aggregate
ConcreteIterator --> Iterator
Aggregate --> Iterator:Creates
ConcreteIterator o--> ConcreteAggregate
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/bb554df1-a5c9-ad9a-8169-cb888506f69c.png)

#Adapter
@startuml
Class Print {
printWeak()
printStrong()
}

Class PrintBanner{
Banner
printWeak()
printStrong()
}

Class Banner{
showWithParen()
ShowWithAster()
}

main --> Print:Uses
PrintBanner --> Print
PrintBanner --> Banner
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/af7ae30f-fa68-adb5-ee03-6d26d042e392.png)

#Template Method
@startuml
Class AbastractClass{
method1()
method2()
method3()
templateMthod()
}

Class ConcreteClass{
method1()
method2()
method3()
}

ConcreteClass --> AbastractClass
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/4149b350-6341-2763-2cb2-4c3140cd0710.png)

#Factory Method
@startuml
package Framework {
    class Creator{
    create()
    factoryMethod()
    }
    class Product{
    method1()
    method2()
    method3()
    }
}

package ConcreteContet {
    class ConcreteCreator{
    factoryMethod()
    }
    class ConcreteProduct{
    method1()
    method2()
    method3()
    }
}

Creator --> Product:Creates
ConcreteCreator --> ConcreteProduct:Creates
ConcreteCreator --> Creator
ConcreteProduct --> Product
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/3a2d3133-0738-2fe0-e077-9a4a797e492f.png)


#Singleton
@startuml
class Singleton{
{static} -singleten
-Singleten()
{static} getInstance()
}
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/dc2e7053-d645-c226-5733-00d717db0fe3.png)


#Prototype
"@startuml
class Client{}
class Prototype{
createClone()
}
class ConcretePrototype{
createClone()
}

Client --> Prototype:Uses
ConcretePrototype --> Prototype
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/493a641b-6b66-6f08-a9ee-4faaf0f2f3e5.png)


#Abstract Factory
@startuml
class Client{}

class Director{
builder
construct()
}

class Builder{
buildPart1()
buildPart2()
buildPart3()
}

class ConcreteBuilder{
buildPart1()
buildPart2()
buildPart3()
getResult()
}

Client --> Director:Uses
Director o--> Builder
ConcreteBuilder --|> Builder
Client --> ConcreteBuilder:Uses
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/d90a8420-bd07-a93d-071d-842bc601c671.png)



#Builder
@startuml
package factory{
	class AbstractProduct1{
	executeA()
	executeB()
	}
	
	class AbstractProduct2{
	doAlpha()
	doBeta()
	}
	
	class AbstractProduct3{
	performOne()
	performTwo()
	}
	
	class AbstractFactory{
	createProduct1()
	createProduct2()
	createProduct3()
	}
}

package Concretefactory{
	class ConcreteProduct1{
	executeA()
	executeB()
	}
	
	class ConcreteProduct2{
	doAlpha()
	doBeta()
	}
	
	class ConcreteProduct3{
	performOne()
	performTwo()
	}
	
	class ConcreteFactory{
	createProduct1()
	createProduct2()
	createProduct3()
	}
}

ConcreteFactory --> ConcreteProduct1:Creates
ConcreteFactory --> ConcreteProduct2:Creates
ConcreteFactory --> ConcreteProduct3:Creates
ConcreteFactory --> AbstractFactory
AbstractFactory --> AbstractProduct1:Creates
AbstractFactory --> AbstractProduct2:Creates
AbstractFactory --> AbstractProduct3:Creates
ConcreteProduct1 --> AbstractProduct1
ConcreteProduct2 --> AbstractProduct2
ConcreteProduct3 --> AbstractProduct3
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/6e39d681-930d-f145-4911-892e5a5e6077.png)

#Bridge
@startuml
class Abstraction{
impl
method1()
method2()
method3()
}

class RefineAbstraction{
refinemethodA()
refinemethodB()
}

class Implementor{
implMethodX()
implMethodY()
}

class ConcreteImplementor{
implMethodX()
implMethodY()
}

Abstraction o--> Implementor
ConcreteImplementor --> Implementor
RefineAbstraction --> Abstraction
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/f14653e9-f57c-a58d-9e0f-d9473b37916b.png)


#Strategy
@startuml
class Context{
Strategy
ContextMethod()
}

class Strategy{
strategyMethod()
}

class ConcreteStrategy1{
strategyMethod()
}

class ConcreteStrategy2{
strategyMethod()
}

Context o--> Strategy
ConcreteStrategy1 --|> Strategy
ConcreteStrategy2 --|> Strategy
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/a0bdcefc-4997-a886-22d1-125b69ebf57e.png)


#Composite
@startuml
class Client{}

class Component{
method1()
method2()
add()
remove()
getChild()
}

class Leaf{
method1()
method2()
}

class Composite{
children
method1()
method2()
add()
remove()
getChild()
}

Client --> Component:Uses
Composite  o--> Component
Composite --|> Component
Leaf --|> Component
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/7e857316-57fe-fe03-fd32-5b8ae56ce6db.png)


#Decorator
@startuml
class Component{
method1()
method2()
method3()
}

class ConcreteComponent{
method1()
method2()
method3()
}

class Decorator{
component
}

class ConcreteDecorator{
method1()
method2()
method3()
}

Decorator o--> Component
Decorator --|> Component
ConcreteComponent --|> Component
ConcreteDecorator --|> Decorator
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/30ae440c-d1a4-04d9-85cb-f4a9f95e7243.png)

#Visitor
@startuml
class Visitor{
visit(ConcreteElementA)
visit(ConcreteElementB)
}

class ConcreteVisitor{
visit(ConcreteElementA)
visit(ConcreteElementB)
}

class ObjectStructure{}

class Element{
accept()
}

class ConcreteElementA{
accept()
}

class ConcreteElementB{
accept()
}

ObjectStructure o--> Element
ConcreteElementA --|> Element
ConcreteElementB --|> Element
ConcreteVisitor --|> Visitor
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/cd90b058-e9ef-cef2-4fa3-df8e26a4d008.png)


#Chain of Responsibility
@startuml
class Client{}

class Handler{
next
request()
}


class ConcreteHandler1{
request()
}


class ConcreteHandler2{
request()
}

Client--> Handler:Request
Handler.next o--> Handler
ConcreteHandler1 --> Handler
ConcreteHandler2 --> Handler
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/278e8813-054a-814f-7900-afb9cbc7e25a.png)


#Facade
@startuml
class Client{}
class Facade{}
class ClassA{}
class ClassB{}
class ClassC{}
class ClassD{}

Client --> Facade:Uses
Facade --> ClassA
Facade --> ClassB
Facade --> ClassC
Facade --> ClassD
ClassA --> ClassB
ClassB --> ClassC
ClassC --> ClassB
ClassD --> ClassC
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/cfb15d04-ddd6-6793-17f9-48faa01b8f4c.png)


#Mediator
@startuml
class Meditator{
createColleagues()
colleagueChanged()
}

class ConcreteMeditator{
ConcreteColleague1
ConcreteColleague2
ConcreteColleague3
createColleagues()
colleagueChanged()
}

class Colleague{
meditator
setMeditator()
controlColleague()
}

class ConcreteColleague1{
controlColleague()
}

class ConcreteColleague2{
controlColleague()
}

class ConcreteColleague3{
controlColleague()
}

ConcreteMeditator --|> Meditator
Colleague o--> Meditator
ConcreteMeditator o--> ConcreteColleague1
ConcreteMeditator o--> ConcreteColleague2
ConcreteMeditator o--> ConcreteColleague3

ConcreteColleague1 --|> Colleague
ConcreteColleague2 --|> Colleague
ConcreteColleague3 --|> Colleague
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/57ec9193-a76a-de90-3533-7e699fcd9f2e.png)


#Observer
@startuml
class Subject{
observers
addObservers()
deleteObservers()
notifyObservers()
getSujectStatus()
}

class Observer{
update()
}

class ConcreteSubject{
getSujectStatus()
}

class ConcreteObserver{
update()
}

Subject o--> Observer:Notifies
ConcreteSubject --|> Subject
ConcreteSubject --|> ConcreteObserver
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/24761793-3ae3-fe72-8310-031839e0a5bb.png)


#Memento
@startuml
class Caretaker{

}

class Originator{
createMemento()
restoreMemento()
}

class Memento{
~ <<wide interface>> getProtectedInfo()
+ <<narrow interface>> getPublicInfo()
}

Caretaker --> Originator:Requests
Caretaker --> Memento
Originator --> Memento:Creates
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/d200eeab-0407-28a1-a59b-c94fc7ef9687.png)


#State
@startuml
class Context{
state
requestX()
requestY()
requestZ()
}

class State{
methodA()
methodB()
methodC()
methodD()
}

class ConcreteState1{
methodA()
methodB()
methodC()
methodD()
}

class ConcreteState2{
methodA()
methodB()
methodC()
methodD()
}

Context o--> State
ConcreteState1 --|> State
ConcreteState2 --|> State
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/1201f6a2-b3b2-cafe-c241-a1637be7934a.png)


#Flyweight
@startuml
class Client{}

class FlyweightFactory{
pool
getFlyweight()
}

class Flyweight{
methodA()
methodB()
}

Client --> Flyweight:Uses
Client --> FlyweightFactory:Uses
FlyweightFactory o--> Flyweight:Creates
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/64517dc3-7da1-3607-d4d0-76a7126c77fd.png)

#Proxy
@startuml
class Client{
}

class Subject{
request1()
request2()
request3()
}

class Proxy{
request1()
request2()
request3()
}

class RealSubject{
request1()
request2()
request3()
}

Client o--> Subject:Uses
Proxy o--> RealSubject:Uses
Proxy --|> Subject
RealSubject --|> Subject
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/35f37912-930d-5e22-4d25-7ee8ffbc4846.png)


#Command
@startuml
class Receiver{
action()
}

class Command{
execute()
}

class ConcreteCommand{
receiver
execute()
}

class Client{}
class Invoker{}

ConcreteCommand o--> Receiver
ConcreteCommand --|> Command
Client --> ConcreteCommand:Creates
Invoker o--> Command
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/34de1b5e-64e1-8a10-136b-fcc781e80321.png)


#Interpreter
@startuml
class Client{}

class Context{
getInforToInterpret()
}

class AbstractExpression{
interpret()
}

class TerminalExpression{
interpret()
}

class NonterminalExpression{
childExpressions
interpret()
}

Client --> Context:Creates
Client --> AbstractExpression:Uses
NonterminalExpression o--> AbstractExpression
NonterminalExpression --|> AbstractExpression
TerminalExpression --|> AbstractExpression
@enduml
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274248/840f982b-0e21-5322-0bdb-d658b5bd9f0b.png)