Skip to content

Commit 022ab28

Browse files
committed
issue iluwatar#333 diagrams and index added
1 parent 10bbf98 commit 022ab28

15 files changed

Lines changed: 165 additions & 140 deletions

File tree

‎factory-kit/etc/factory-kit.png‎

36.7 KB
Loading

‎factory-kit/etc/factory-kit.ucls‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<class-diagram version="1.1.9" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
3+
realizations="true" associations="true" dependencies="false" nesting-relationships="true">
4+
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
5+
sort-features="false" accessors="true" visibility="true">
6+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
7+
<operations public="true" package="true" protected="true" private="true" static="true"/>
8+
</classifier-display>
9+
<association-display labels="true" multiplicity="true"/>
10+
</class-diagram>

‎factory-kit/index.md‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,18 @@ tags:
1010
- Functional
1111
---
1212

13-
## Also known as
14-
Virtual Constructor
15-
1613
## Intent
1714
Define factory of immutable content with separated builder and factory interfaces.
1815

19-
![alt text](./etc/factory-kit_1.png "Factory Kit")
16+
![alt text](./etc/factory-kit.png "Factory Kit")
2017

2118
## Applicability
2219
Use the Factory Kit pattern when
2320

2421
* a class can't anticipate the class of objects it must create
25-
* you just want a new instance of custom builder instead of global one
26-
* a class wants its subclasses to specify the objects it creates
27-
* classes delegate responsibility to one of several helper subclasses, and you want to localize the knowledge of which helper subclass is the delegate
22+
* you just want a new instance of a custom builder instead of the global one
23+
* you explicitly want to define types of objects, that factory can build
24+
* you want a separated builder and creator interface
2825

2926
## Credits
3027

‎factory-kit/src/main/java/com/iluwatar/factorykit/App.java‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
public class App {
44

5-
public static void main(String[] args) {
6-
WeaponFactory factory = WeaponFactory.factory(builder -> {
7-
builder.add(WeaponType.SWORD, Sword::new);
8-
builder.add(WeaponType.AXE, Axe::new);
9-
builder.add(WeaponType.SPEAR, Spear::new);
10-
builder.add(WeaponType.BOW, Bow::new);
11-
});
12-
Weapon axe = factory.create(WeaponType.AXE);
13-
System.out.println(axe);
14-
}
5+
public static void main(String[] args) {
6+
WeaponFactory factory = WeaponFactory.factory(builder -> {
7+
builder.add(WeaponType.SWORD, Sword::new);
8+
builder.add(WeaponType.AXE, Axe::new);
9+
builder.add(WeaponType.SPEAR, Spear::new);
10+
builder.add(WeaponType.BOW, Bow::new);
11+
});
12+
Weapon axe = factory.create(WeaponType.AXE);
13+
System.out.println(axe);
14+
}
1515
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.iluwatar.factorykit;
22

33
public class Axe implements Weapon {
4-
@Override public String toString() {
5-
return "Axe{}";
6-
}
4+
@Override
5+
public String toString() {
6+
return "Axe";
7+
}
78
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.iluwatar.factorykit;
22

3-
/**
4-
* Created by crossy on 2016-01-16.
5-
*/
63
public class Bow implements Weapon {
4+
@Override
5+
public String toString() {
6+
return "Bow";
7+
}
78
}

‎factory-kit/src/main/java/com/iluwatar/factorykit/Builder.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import java.util.function.Supplier;
44

5+
/**
6+
* Functional interface that allows adding builder with name to the factory
7+
*/
58
public interface Builder {
6-
void add(WeaponType name, Supplier<Weapon> supplier);
9+
void add(WeaponType name, Supplier<Weapon> supplier);
710
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.iluwatar.factorykit;
22

33
public class Spear implements Weapon {
4-
@Override public String toString() {
5-
return "Spear{}";
6-
}
4+
@Override
5+
public String toString() {
6+
return "Spear";
7+
}
78
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.iluwatar.factorykit;
22

33
public class Sword implements Weapon {
4-
@Override public String toString() {
5-
return "Sword{}";
6-
}
4+
@Override
5+
public String toString() {
6+
return "Sword";
7+
}
78
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
package com.iluwatar.factorykit;
22

3+
/**
4+
* Interface representing weapon
5+
*/
36
public interface Weapon {
47
}

0 commit comments

Comments
 (0)