Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

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

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

Iterator

@startuml
class Aggregate <>{
iterator()
}

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

class ConcreteAggregate {
iterator()
}

Class ConcreteIterator{
aggregate
hasNext()
next()
}

ConcreteAggregate --> Aggregate
ConcreteIterator --> Iterator
Aggregate --> Iterator:Creates
ConcreteIterator o--> ConcreteAggregate
@enduml
image.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

Template Method

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

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

ConcreteClass --> AbastractClass
@enduml
image.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

Singleton

@startuml
class Singleton{
{static} -singleten
-Singleten()
{static} getInstance()
}
@enduml
image.png

Prototype

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

Client --> Prototype:Uses
ConcretePrototype --> Prototype
@enduml
image.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

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

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

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

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

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

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

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

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

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

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

Memento

@startuml
class Caretaker{

}

class Originator{
createMemento()
restoreMemento()
}

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

Caretaker --> Originator:Requests
Caretaker --> Memento
Originator --> Memento:Creates
@enduml
image.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

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

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

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

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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away