#590 Add explanation for Builder

This commit is contained in:
Ilkka Seppälä
2017-08-13 17:34:05 +03:00
parent cbba487ff8
commit f6c8bfbc39
6 changed files with 98 additions and 263 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

View File

@ -1,162 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<class-diagram version="1.1.8" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
realizations="true" associations="true" dependencies="false" nesting-relationships="true">
<enumeration id="1" language="java" name="com.iluwatar.builder.HairType" project="builder"
file="/builder/src/main/java/com/iluwatar/builder/HairType.java" binary="false" corner="BOTTOM_RIGHT">
<position height="214" width="189" x="177" y="419"/>
<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>
</enumeration>
<enumeration id="2" language="java" name="com.iluwatar.builder.Weapon" project="builder"
file="/builder/src/main/java/com/iluwatar/builder/Weapon.java" binary="false" corner="BOTTOM_RIGHT">
<position height="196" width="171" x="406" y="419"/>
<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>
</enumeration>
<enumeration id="3" language="java" name="com.iluwatar.builder.HairColor" project="builder"
file="/builder/src/main/java/com/iluwatar/builder/HairColor.java" binary="false" corner="BOTTOM_RIGHT">
<position height="196" width="144" x="-204" y="419"/>
<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>
</enumeration>
<class id="4" language="java" name="com.iluwatar.builder.Hero.Builder" project="builder"
file="/builder/src/main/java/com/iluwatar/builder/Hero.java" binary="false" corner="BOTTOM_RIGHT">
<position height="196" width="234" x="20" y="183"/>
<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>
<enumeration id="5" language="java" name="com.iluwatar.builder.Armor" project="builder"
file="/builder/src/main/java/com/iluwatar/builder/Armor.java" binary="false" corner="BOTTOM_RIGHT">
<position height="196" width="145" x="617" y="419"/>
<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>
</enumeration>
<enumeration id="6" language="java" name="com.iluwatar.builder.Profession" project="builder"
file="/builder/src/main/java/com/iluwatar/builder/Profession.java" binary="false" corner="BOTTOM_RIGHT">
<position height="178" width="157" x="-20" y="419"/>
<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>
</enumeration>
<class id="7" language="java" name="com.iluwatar.builder.Hero" project="builder"
file="/builder/src/main/java/com/iluwatar/builder/Hero.java" binary="false" corner="BOTTOM_RIGHT">
<position height="232" width="178" x="275" y="-89"/>
<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>
<association id="8">
<bendpoint x="284" y="183"/>
<end type="SOURCE" refId="7" navigable="false">
<attribute id="9" name="hairType"/>
<multiplicity id="10" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="1" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="11">
<end type="SOURCE" refId="4" navigable="false">
<attribute id="12" name="weapon"/>
<multiplicity id="13" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="2" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="14">
<end type="SOURCE" refId="4" navigable="false">
<attribute id="15" name="profession"/>
<multiplicity id="16" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="6" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="17">
<end type="SOURCE" refId="4" navigable="false">
<attribute id="18" name="hairColor"/>
<multiplicity id="19" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="3" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="20">
<bendpoint x="350" y="183"/>
<end type="SOURCE" refId="7" navigable="false">
<attribute id="21" name="weapon"/>
<multiplicity id="22" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="2" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="23">
<end type="SOURCE" refId="4" navigable="false">
<attribute id="24" name="hairType"/>
<multiplicity id="25" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="1" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<nesting id="26">
<end type="SOURCE" refId="7"/>
<end type="TARGET" refId="4"/>
</nesting>
<association id="27">
<end type="SOURCE" refId="4" navigable="false">
<attribute id="28" name="armor"/>
<multiplicity id="29" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="5" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="30">
<bendpoint x="-11" y="183"/>
<end type="SOURCE" refId="7" navigable="false">
<attribute id="31" name="profession"/>
<multiplicity id="32" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="6" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="33">
<bendpoint x="-32" y="183"/>
<end type="SOURCE" refId="7" navigable="false">
<attribute id="34" name="hairColor"/>
<multiplicity id="35" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="3" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="36">
<bendpoint x="455" y="183"/>
<end type="SOURCE" refId="7" navigable="false">
<attribute id="37" name="armor"/>
<multiplicity id="38" 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,100 +0,0 @@
@startuml
package com.iluwatar.builder {
class App {
- LOGGER : Logger {static}
+ App()
+ main(args : String[]) {static}
}
enum Armor {
+ CHAIN_MAIL {static}
+ CLOTHES {static}
+ LEATHER {static}
+ PLATE_MAIL {static}
- title : String
+ toString() : String
+ valueOf(name : String) : Armor {static}
+ values() : Armor[] {static}
}
enum HairColor {
+ BLACK {static}
+ BLOND {static}
+ BROWN {static}
+ RED {static}
+ WHITE {static}
+ toString() : String
+ valueOf(name : String) : HairColor {static}
+ values() : HairColor[] {static}
}
enum HairType {
+ BALD {static}
+ CURLY {static}
+ LONG_CURLY {static}
+ LONG_STRAIGHT {static}
+ SHORT {static}
- title : String
+ toString() : String
+ valueOf(name : String) : HairType {static}
+ values() : HairType[] {static}
}
class Hero {
- armor : Armor
- hairColor : HairColor
- hairType : HairType
- name : String
- profession : Profession
- weapon : Weapon
- Hero(builder : Builder)
+ getArmor() : Armor
+ getHairColor() : HairColor
+ getHairType() : HairType
+ getName() : String
+ getProfession() : Profession
+ getWeapon() : Weapon
+ toString() : String
}
class Builder {
- armor : Armor
- hairColor : HairColor
- hairType : HairType
- name : String
- profession : Profession
- weapon : Weapon
+ Builder(profession : Profession, name : String)
+ build() : Hero
+ withArmor(armor : Armor) : Builder
+ withHairColor(hairColor : HairColor) : Builder
+ withHairType(hairType : HairType) : Builder
+ withWeapon(weapon : Weapon) : Builder
}
enum Profession {
+ MAGE {static}
+ PRIEST {static}
+ THIEF {static}
+ WARRIOR {static}
+ toString() : String
+ valueOf(name : String) : Profession {static}
+ values() : Profession[] {static}
}
enum Weapon {
+ AXE {static}
+ BOW {static}
+ DAGGER {static}
+ SWORD {static}
+ WARHAMMER {static}
+ toString() : String
+ valueOf(name : String) : Weapon {static}
+ values() : Weapon[] {static}
}
}
Builder ..+ Hero
Hero --> "-profession" Profession
Hero --> "-armor" Armor
Builder --> "-hairColor" HairColor
Builder --> "-weapon" Weapon
Builder --> "-hairType" HairType
Hero --> "-hairColor" HairColor
Builder --> "-profession" Profession
Hero --> "-hairType" HairType
Hero --> "-weapon" Weapon
Builder --> "-armor" Armor
@enduml

Binary file not shown.

Before

Width:  |  Height:  |  Size: 104 KiB