PlantUmlでデザインパターン
PlantUMLの勉強のため、書籍「実践!!デザインパターン」のクラス図を記述してみました。
【Singleton(シングルトン)】
@startuml
class Foo {
-singleton Foo = null
-Foo()
+GetInstance() : Foo
}
object "シングルトン : Foo" as シングルトン
Foo ..> シングルトン : <<create>>
@enduml
【Prototype(プロトタイプ)】
@startuml
class Prototype {
+CreateClone()
}
class ConcretePrototype{
+CreateClone()
}
object "a client" as client
ConcretePrototype .up.|> Prototype
client -right-> Prototype : <<uses>>
@enduml
【Builder(ビルダー)】
@startuml
class Director {
Construct()
}
class Builder{
BuildPartA()
BuildParB()
}
class ConcreteBuilder{
BuildPartA()
BuildPartB()
GetResult()
}
object "a client" as client
client -right-> Director : <<uses>>
Director o-right-> Builder
Builder <|-down- ConcreteBuilder
client --> ConcreteBuilder : <<uses>>
@enduml
【Factory Method(ファクトリ・メソッド)】
@startuml
class Product {
}
class ConcreteProductA {
}
class ConcreteProductB {
}
class Creator {
+AnOperation()
#FactoryMethod()
}
class ConcreteCreatorA {
#FactoryMethod()
}
class ConcreteCreatorB {
#FactoryMethod()
}
Product <|-down- ConcreteProductA
Product <|-down- ConcreteProductB
Creator <|-down- ConcreteCreatorA
Creator <|-down- ConcreteCreatorB
ConcreteProductA <.right. ConcreteCreatorA
ConcreteProductB <.right. ConcreteCreatorB
@enduml
【Abstract Factory(抽象ファクトリ)】
@startuml
class AbstractA{
ActionA()
}
class FooA{
ActionA()
}
class AbstractFactory{
+CreateProduct()
CreateA()
CreateB()
}
class FooFactory{
CreateA()
CreateB()
}
class AbstractB{
ActionB()
}
class FooB{
ActionB()
}
AbstractFactory <|-down- FooFactory
AbstractA <|-down- FooA
AbstractB <|-down- FooB
AbstractFactory .left.> AbstractA : <<create>>
AbstractFactory .right.> AbstractB : <<create>>
FooFactory .left.> FooA : <<create>>
FooFactory .right.> FooB : <<create>>
@enduml
【Adaptor(アダプタ)】
@startuml
class Adaptor{
Adaptee : Adaptee
Operation()
}
class Adaptee{
Method()
}
class Target{
Operation()
}
object Client
Adaptee -down-o Adaptor
Adaptor -right-o Target
Client -> Target : <<uses>>
@enduml
【Bridge(ブリッジ)】
@startuml
class Abstraction{
impl
Method1()
}
class Implementor{
ImplMethod1()
}
class RefinedAbstraction{
RefinedMethodA()
}
class ConcreteImplementor{
ImplMethod1()
}
Abstraction <|-down- RefinedAbstraction
Abstraction o-right-> Implementor : impl
Implementor <|.down. ConcreteImplementor
@enduml
【Composite(コンポジット;合成)】
@startuml
class Component{
Operation1()
Add(Component)
Remover(Component)
GetChild(key)
}
class Leaf{
Operation1()
}
class Composite{
children : Component
Operation1()
Add(Component)
Remove(Component)
GetChild(key)
}
object "a clinet" as clinet
clinet -right-> Component : <<uses>>
Component <|-down- Leaf
Component <|-down- Composite
Composite o--> Component : children
@enduml
【Decorator(デコレータ;装飾者)】
@startuml
class Component{
Operation1()
}
class ConcreteComponet{
Operation1()
}
class Decorator{
componet : Component
}
class ConcreteDecorator{
Operation1()
}
object "a client" as client
client -right-> Component : <<uses>>
ConcreteComponet -up-|> Component
Decorator -up-|> Component
Decorator o-up-> Component : component
ConcreteDecorator -up-|> Decorator
@enduml
【Facade(ファサード;重要な正面)】
@startuml
class Facade{
Operation()
}
class Class1{
Operation1()
}
class Class2{
Operation2()
}
class Class3{
Operation3()
}
object "a client" as client
client -right-> Facade : <<uses>>
Facade -down-> Class1
Facade -down-> Class2
Facade -down-> Class3
@enduml
【Flyweight(フライ級)】
@startuml
class FlyweightFactory{
pool : Map
GetFlyweight(Object)
CreateFlyweight(List)
}
class Flyweight{
Operation1()
}
class SharedConcreteFlyweight{
Operation1()
}
class UnsharedConcreteFlyweight{
factory : FlyweightFactory
Operation1()
}
object "a client" as client
client -down-> Flyweight : <<uses>>
client -right-> FlyweightFactory : <<uses>>
FlyweightFactory ..> Flyweight
FlyweightFactory o-down-> SharedConcreteFlyweight
Flyweight o-right-> SharedConcreteFlyweight
Flyweight o--> UnsharedConcreteFlyweight
UnsharedConcreteFlyweight o-down-> FlyweightFactory
@enduml
【Proxy(プロキシー;代理)】
@startuml
class Subject{
属性(共通)
Request1()
}
class Proxy{
Request1()
}
class RealSubject{
属性(非共通)
Request1()
}
object "a client" as client
client -right-> Subject : <<uses>>
Proxy -up-|> Subject
RealSubject -up-|> Subject
Proxy o-right-> RealSubject : <<uses>>
note left of Proxy
一部情報を保持
end note
note right of RealSubject
全情報を保持
end note
@enduml
【Templete Method(テンプレート・メソッド)】
@startuml
class Foo{
+MainDo()
#Sub1()
#Sub2()
}
class Concrete1{
#Sub1()
#Sub2()
}
class Concrete2{
#Sub1()
#Sub2()
}
Concrete1 -up-|>Foo
Concrete2 -up-|>Foo
@enduml
【Chain of Responsibility(責任のたらい回し)】
@startuml
class Handler{
next : Handler
Request()
}
class ConcreteHandler1{
Request()
}
class ConcreteHandler2{
Request()
}
object "a client" as client
client -right-> Handler : <<uses>>
Handler --> Handler : next
ConcreteHandler1 -up-|> Handler
ConcreteHandler2 -up-|> Handler
@enduml
【Commando(コマンド)】
@startuml
class Command{
Execute()
}
class ConcreteCommand{
reciver : Receiver
ExeCute()
}
class Receiver{
Action()
}
object Invoker
object "a client" as client
client -up-> Invoker : <<uses>>
Invoker o-right-> Command
ConcreteCommand o-right->Receiver
ConcreteCommand -up-|> Command
@enduml
【Interpreter(インタープリタ)】
@startuml
class Context{
GetInfoToInterpret()
}
class AbstractExpression{
Interpret(Context)
}
class TerminalExpression{
Interpret(Context)
}
class NonTerminalExpression{
childExpressions
Interpret(Context)
}
object Client
Client -right-> Context : <<creates>>
Client -down-> AbstractExpression
TerminalExpression -up-|> AbstractExpression
NonTerminalExpression -up-|> AbstractExpression
NonTerminalExpression o--> AbstractExpression
@enduml
【Iterate(イテレート)】
@startuml
interface Aggregate{
Iterator()
}
Interface Iterator{
HasNext()
Next()
}
class ConcreteAggregate{
Iterator()
}
class ConcreteIterator{
Aggregate : ConcreteAggregate
HasNext()
Next()
}
Aggregate .right.> Iterator : <<creates>>
ConcreteAggregate .up.|> Aggregate
ConcreteIterator o-left-> ConcreteAggregate
ConcreteIterator .up.|> Iterator
@enduml
【Observer(オブザーバ)】
@startuml
class Subject{
observers : List
AddObserver()
DeleteObserver()
NotifyObservers()
GetSubjectStatus()
}
class Observer{
Update()
}
class ConcreteSubject{
GetSubjectStatus()
}
class ConcreteObserver{
Update()
}
Subject o-right-> "0..n" Observer : 更新を通知
ConcreteSubject -up-|> Subject
ConcreteObserver -up-> Observer
@enduml
【Mediate(メディエート;仲介)】
@startuml
class Mediator{
CreateCollegues()
ColleagueChanged()
}
class Colleague{
mediator
SetMediator()
ControlColleague()
}
class ConcreteMediator{
concreteColleague1
concreteColleague2
concreteColleague3
CreateColleagues()
ColleagueChanged()
}
class ConcreteColleague1{
ControlColleague()
}
class ConcreteColleague2{
ControlColleague()
}
class ConcreteColleague3{
ControlColleague()
}
left to right direction
ConcreteMediator o--> ConcreteColleague1
ConcreteMediator o--> ConcreteColleague3
ConcreteMediator o--> ConcreteColleague2
ConcreteColleague1 --|> Colleague
ConcreteColleague2 --|> Colleague
ConcreteColleague3 --|> Colleague
Colleague o-left-> Mediator
ConcreteMediator -up-|> Mediator
@enduml
【Memento(メメント;記念)】
@startuml
class Caretaker{
}
class Originator{
CreateMemento()
RestoreMemento(Memento)
}
class Memento{
<<wide interface()>>
~GetProtectedInfo()
<<narrow interface()>>
PetPublicInfo()
}
Caretaker -right-> Originator : <<Requests>>
Originator .down.> Memento : <<Creates>>
Caretaker o--> Memento
@enduml
【State(ステート)】
@startuml
class Context{
Request1()
Request2()
}
class State{
MethodA() : State
MethodB() : State
MethodC() : State
}
class ConcreteState1{
MethodA() : State
MethodB() : State
MethodC() : State
}
class ConcreteState2{
MethodA() : State
MethodB() : State
MethodC() : State
}
Context o-right-> State
ConcreteState1 -up-|> State
ConcreteState2 -up-|> State
@enduml
【Strategy(戦略)】
@startuml
class Context{
strategy : Strategy
ContextMethod()
}
class Strategy{
StrategyMethod()
}
class ConcreteStrategy1{
StrategyMethod()
}
class ConcreteStrategy2{
StrategyMethod()
}
Context o-right-> Strategy
ConcreteStrategy1 --|> Strategy
ConcreteStrategy2 --|> Strategy
@enduml
【Visitor(訪問者)】
@startuml
class Visitor{
Visit(concreteElement1)
Visit(concreteElement2)
}
class Element{
Accept(Visitor)
}
class ConcreteVisitor{
Visit(concreteElement1)
Visit(concreteElement2)
}
class ConcreteElement1{
Accept(Visitor)
}
class ConcreteElement2{
Accept(Visitor)
}
object objectStructure
Visitor .right.|> Element
Visitor <|.right. Element
Element -down-o objectStructure
ConcreteVisitor --|> Visitor
ConcreteElement1 -up-|> Element
ConcreteElement2 -up-|> Element
@enduml