#1021 Checkstyle changes for Factory Method
This commit is contained in:
parent
7dc47da131
commit
47ae477a56
@ -27,14 +27,13 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* The Factory Method is a creational design pattern which uses factory methods to deal with the
|
* The Factory Method is a creational design pattern which uses factory methods to deal with the
|
||||||
* problem of creating objects without specifying the exact class of object that will be created.
|
* problem of creating objects without specifying the exact class of object that will be created.
|
||||||
* This is done by creating objects via calling a factory method either specified in an interface
|
* This is done by creating objects via calling a factory method either specified in an interface
|
||||||
* and implemented by child classes, or implemented in a base class and optionally overridden by
|
* and implemented by child classes, or implemented in a base class and optionally overridden by
|
||||||
* derived classes—rather than by calling a constructor.
|
* derived classes—rather than by calling a constructor.
|
||||||
* <p>
|
*
|
||||||
* In this Factory Method example we have an interface ({@link Blacksmith}) with a method for
|
* <p>In this Factory Method example we have an interface ({@link Blacksmith}) with a method for
|
||||||
* creating objects ({@link Blacksmith#manufactureWeapon}). The concrete subclasses (
|
* creating objects ({@link Blacksmith#manufactureWeapon}). The concrete subclasses (
|
||||||
* {@link OrcBlacksmith}, {@link ElfBlacksmith}) then override the method to produce objects of
|
* {@link OrcBlacksmith}, {@link ElfBlacksmith}) then override the method to produce objects of
|
||||||
* their liking.
|
* their liking.
|
||||||
@ -59,7 +58,7 @@ public class App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point.
|
||||||
*
|
*
|
||||||
* @param args command line args
|
* @param args command line args
|
||||||
*/
|
*/
|
||||||
|
@ -24,9 +24,7 @@
|
|||||||
package com.iluwatar.factory.method;
|
package com.iluwatar.factory.method;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* The interface containing method for producing objects.
|
* The interface containing method for producing objects.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface Blacksmith {
|
public interface Blacksmith {
|
||||||
|
|
||||||
|
@ -27,18 +27,17 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Concrete subclass for creating new objects.
|
* Concrete subclass for creating new objects.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ElfBlacksmith implements Blacksmith {
|
public class ElfBlacksmith implements Blacksmith {
|
||||||
|
|
||||||
private static Map<WeaponType, ElfWeapon> ELFARSENAL;
|
private static Map<WeaponType, ElfWeapon> ELFARSENAL;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ELFARSENAL= new HashMap<>(WeaponType.values().length);
|
ELFARSENAL = new HashMap<>(WeaponType.values().length);
|
||||||
for (WeaponType type : WeaponType.values()) {
|
for (WeaponType type : WeaponType.values()) {
|
||||||
ELFARSENAL.put(type, new ElfWeapon(type));
|
ELFARSENAL.put(type, new ElfWeapon(type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -27,18 +27,17 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Concrete subclass for creating new objects.
|
* Concrete subclass for creating new objects.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class OrcBlacksmith implements Blacksmith {
|
public class OrcBlacksmith implements Blacksmith {
|
||||||
|
|
||||||
private static Map<WeaponType, OrcWeapon> ORCARSENAL;
|
private static Map<WeaponType, OrcWeapon> ORCARSENAL;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ORCARSENAL= new HashMap<>(WeaponType.values().length);
|
ORCARSENAL = new HashMap<>(WeaponType.values().length);
|
||||||
for (WeaponType type : WeaponType.values()) {
|
for (WeaponType type : WeaponType.values()) {
|
||||||
ORCARSENAL.put(type, new OrcWeapon(type));
|
ORCARSENAL.put(type, new OrcWeapon(type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -24,9 +24,7 @@
|
|||||||
package com.iluwatar.factory.method;
|
package com.iluwatar.factory.method;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* WeaponType enumeration.
|
||||||
* WeaponType enumeration
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public enum WeaponType {
|
public enum WeaponType {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user