File tree Expand file tree Collapse file tree 4 files changed +24
-5
lines changed
factory-kit/src/main/java/com/iluwatar/factorykit Expand file tree Collapse file tree 4 files changed +24
-5
lines changed Original file line number Diff line number Diff line change 11package com .iluwatar .factorykit ;
22
33public class App {
4-
4+ /**
5+ * Program entry point.
6+ *
7+ * @param args @param args command line args
8+ */
59 public static void main (String [] args ) {
610 WeaponFactory factory = WeaponFactory .factory (builder -> {
711 builder .add (WeaponType .SWORD , Sword ::new );
Original file line number Diff line number Diff line change 11package com .iluwatar .factorykit ;
22
33/**
4- * Interface representing weapon
4+ * Interface representing weapon.
55 */
66public interface Weapon {
77}
Original file line number Diff line number Diff line change 55import java .util .function .Supplier ;
66
77/**
8- * Functional interface that represents factory kit. Instance created locally gives an opportunity to strictly define
9- * which objects types the instance of a factory would be able to create. Factory is just a placeholder for builders with
10- * create method to initialize new objects.
8+ * Functional interface, an example of the factory-kit design pattern.
9+ * <br>Instance created locally gives an opportunity to strictly define
10+ * which objects types the instance of a factory will be able to create.
11+ * <br>Factory is a placeholder for {@link Builder}s
12+ * with {@link WeaponFactory#create(WeaponType)} method to initialize new objects.
1113 */
1214public interface WeaponFactory {
1315
16+ /**
17+ * Creates an instance of the given type.
18+ * @param name representing enum of an object type to be created.
19+ * @return new instance of a requested class implementing {@link Weapon} interface.
20+ */
1421 Weapon create (WeaponType name );
1522
23+ /**
24+ * Creates factory - placeholder for specified {@link Builder}s.
25+ * @param consumer for the new builder to the factory.
26+ * @return factory with specified {@link Builder}s
27+ */
1628 static WeaponFactory factory (Consumer <Builder > consumer ) {
1729 HashMap <WeaponType , Supplier <Weapon >> map = new HashMap <>();
1830 consumer .accept (map ::put );
Original file line number Diff line number Diff line change 11package com .iluwatar .factorykit ;
22
3+ /**
4+ * Enumerates {@link Weapon} types
5+ */
36public enum WeaponType {
47 SWORD , AXE , BOW , SPEAR
58}
You can’t perform that action at this time.
0 commit comments