File tree Expand file tree Collapse file tree 5 files changed +14
-21
lines changed
factory-method/src/main/java/com/iluwatar/factory/method Expand file tree Collapse file tree 5 files changed +14
-21
lines changed Original file line number Diff line number Diff line change 27
27
import org .slf4j .LoggerFactory ;
28
28
29
29
/**
30
- *
31
30
* The Factory Method is a creational design pattern which uses factory methods to deal with the
32
31
* problem of creating objects without specifying the exact class of object that will be created.
33
32
* This is done by creating objects via calling a factory method either specified in an interface
34
33
* and implemented by child classes, or implemented in a base class and optionally overridden by
35
34
* derived classes—rather than by calling a constructor.
36
- * <p>
37
- * In this Factory Method example we have an interface ({@link Blacksmith}) with a method for
35
+ *
36
+ * <p> In this Factory Method example we have an interface ({@link Blacksmith}) with a method for
38
37
* creating objects ({@link Blacksmith#manufactureWeapon}). The concrete subclasses (
39
38
* {@link OrcBlacksmith}, {@link ElfBlacksmith}) then override the method to produce objects of
40
39
* their liking.
@@ -59,7 +58,7 @@ public App(Blacksmith blacksmith) {
59
58
}
60
59
61
60
/**
62
- * Program entry point
61
+ * Program entry point.
63
62
*
64
63
* @param args command line args
65
64
*/
Original file line number Diff line number Diff line change 24
24
package com .iluwatar .factory .method ;
25
25
26
26
/**
27
- *
28
27
* The interface containing method for producing objects.
29
- *
30
28
*/
31
29
public interface Blacksmith {
32
30
Original file line number Diff line number Diff line change 27
27
import java .util .Map ;
28
28
29
29
/**
30
- *
31
30
* Concrete subclass for creating new objects.
32
- *
33
31
*/
34
32
public class ElfBlacksmith implements Blacksmith {
35
33
36
34
private static Map <WeaponType , ElfWeapon > ELFARSENAL ;
35
+
37
36
static {
38
- ELFARSENAL = new HashMap <>(WeaponType .values ().length );
39
- for (WeaponType type : WeaponType .values ()) {
40
- ELFARSENAL .put (type , new ElfWeapon (type ));
41
- }
37
+ ELFARSENAL = new HashMap <>(WeaponType .values ().length );
38
+ for (WeaponType type : WeaponType .values ()) {
39
+ ELFARSENAL .put (type , new ElfWeapon (type ));
40
+ }
42
41
}
43
42
44
43
@ Override
Original file line number Diff line number Diff line change 27
27
import java .util .Map ;
28
28
29
29
/**
30
- *
31
30
* Concrete subclass for creating new objects.
32
- *
33
31
*/
34
32
public class OrcBlacksmith implements Blacksmith {
35
33
36
34
private static Map <WeaponType , OrcWeapon > ORCARSENAL ;
35
+
37
36
static {
38
- ORCARSENAL = new HashMap <>(WeaponType .values ().length );
39
- for (WeaponType type : WeaponType .values ()) {
40
- ORCARSENAL .put (type , new OrcWeapon (type ));
41
- }
37
+ ORCARSENAL = new HashMap <>(WeaponType .values ().length );
38
+ for (WeaponType type : WeaponType .values ()) {
39
+ ORCARSENAL .put (type , new OrcWeapon (type ));
40
+ }
42
41
}
43
42
44
43
@ Override
Original file line number Diff line number Diff line change 24
24
package com .iluwatar .factory .method ;
25
25
26
26
/**
27
- *
28
- * WeaponType enumeration
29
- *
27
+ * WeaponType enumeration.
30
28
*/
31
29
public enum WeaponType {
32
30
You can’t perform that action at this time.
0 commit comments