#590 Add explanation to Decorator pattern

This commit is contained in:
Ilkka Seppälä
2017-09-02 23:10:39 +03:00
parent 6c9e005a79
commit 9d2f0c6c71
8 changed files with 103 additions and 173 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

View File

@ -1,76 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<class-diagram version="1.1.11" icons="true" automaticImage="PNG" always-add-relationships="false"
generalizations="true" realizations="true" associations="true" dependencies="false" nesting-relationships="true"
router="FAN">
<class id="1" language="java" name="com.iluwatar.decorator.App" project="decorator"
file="/decorator/src/main/java/com/iluwatar/decorator/App.java" binary="false" corner="BOTTOM_RIGHT">
<position height="113" width="114" x="177" y="237"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="2" language="java" name="com.iluwatar.decorator.SimpleTroll" project="decorator"
file="/decorator/src/main/java/com/iluwatar/decorator/SimpleTroll.java" binary="false" corner="BOTTOM_RIGHT">
<position height="149" width="125" x="496" y="237"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="3" language="java" name="com.iluwatar.decorator.ClubbedTroll" project="decorator"
file="/decorator/src/main/java/com/iluwatar/decorator/ClubbedTroll.java" binary="false" corner="BOTTOM_RIGHT">
<position height="149" width="125" x="249" y="426"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="4" language="java" name="com.iluwatar.decorator.TrollDecorator" project="decorator"
file="/decorator/src/main/java/com/iluwatar/decorator/TrollDecorator.java" binary="false" corner="BOTTOM_RIGHT">
<position height="149" width="125" x="331" y="237"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<interface id="5" language="java" name="com.iluwatar.decorator.Troll" project="decorator"
file="/decorator/src/main/java/com/iluwatar/decorator/Troll.java" binary="false" corner="BOTTOM_RIGHT">
<position height="113" width="125" x="414" y="426"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</interface>
<realization id="6">
<end type="SOURCE" refId="4"/>
<end type="TARGET" refId="5"/>
</realization>
<generalization id="7">
<end type="SOURCE" refId="3"/>
<end type="TARGET" refId="4"/>
</generalization>
<realization id="8">
<end type="SOURCE" refId="2"/>
<end type="TARGET" refId="5"/>
</realization>
<association id="9">
<end type="SOURCE" refId="4" navigable="false">
<attribute id="10" name="decorated"/>
<multiplicity id="11" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="5" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</classifier-display>
<association-display labels="true" multiplicity="true"/>
</class-diagram>

View File

@ -1,38 +0,0 @@
@startuml
package com.iluwatar.decorator {
class App {
- LOGGER : Logger {static}
+ App()
+ main(args : String[]) {static}
}
class ClubbedTroll {
- LOGGER : Logger {static}
+ ClubbedTroll(decorated : Troll)
+ attack()
+ getAttackPower() : int
}
class SimpleTroll {
- LOGGER : Logger {static}
+ SimpleTroll()
+ attack()
+ fleeBattle()
+ getAttackPower() : int
}
interface Troll {
+ attack() {abstract}
+ fleeBattle() {abstract}
+ getAttackPower() : int {abstract}
}
class TrollDecorator {
- decorated : Troll
+ TrollDecorator(decorated : Troll)
+ attack()
+ fleeBattle()
+ getAttackPower() : int
}
}
TrollDecorator --> "-decorated" Troll
ClubbedTroll --|> TrollDecorator
SimpleTroll ..|> Troll
TrollDecorator ..|> Troll
@enduml