File tree Expand file tree Collapse file tree
factory-method/src/main/java/com/iluwatar/factory/method Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2727import org .slf4j .LoggerFactory ;
2828
2929/**
30- *
3130 * The Factory Method is a creational design pattern which uses factory methods to deal with the
3231 * problem of creating objects without specifying the exact class of object that will be created.
3332 * This is done by creating objects via calling a factory method either specified in an interface
3433 * and implemented by child classes, or implemented in a base class and optionally overridden by
3534 * 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
3837 * creating objects ({@link Blacksmith#manufactureWeapon}). The concrete subclasses (
3938 * {@link OrcBlacksmith}, {@link ElfBlacksmith}) then override the method to produce objects of
4039 * their liking.
@@ -59,7 +58,7 @@ public App(Blacksmith blacksmith) {
5958 }
6059
6160 /**
62- * Program entry point
61+ * Program entry point.
6362 *
6463 * @param args command line args
6564 */
Original file line number Diff line number Diff line change 2424package com .iluwatar .factory .method ;
2525
2626/**
27- *
2827 * The interface containing method for producing objects.
29- *
3028 */
3129public interface Blacksmith {
3230
Original file line number Diff line number Diff line change 2727import java .util .Map ;
2828
2929/**
30- *
3130 * Concrete subclass for creating new objects.
32- *
3331 */
3432public class ElfBlacksmith implements Blacksmith {
3533
3634 private static Map <WeaponType , ElfWeapon > ELFARSENAL ;
35+
3736 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+ }
4241 }
4342
4443 @ Override
Original file line number Diff line number Diff line change 2727import java .util .Map ;
2828
2929/**
30- *
3130 * Concrete subclass for creating new objects.
32- *
3331 */
3432public class OrcBlacksmith implements Blacksmith {
3533
3634 private static Map <WeaponType , OrcWeapon > ORCARSENAL ;
35+
3736 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+ }
4241 }
4342
4443 @ Override
Original file line number Diff line number Diff line change 2424package com .iluwatar .factory .method ;
2525
2626/**
27- *
28- * WeaponType enumeration
29- *
27+ * WeaponType enumeration.
3028 */
3129public enum WeaponType {
3230
You can’t perform that action at this time.
0 commit comments