Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions factory-method/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ public interface Blacksmith {

public class ElfBlacksmith implements Blacksmith {
public Weapon manufactureWeapon(WeaponType weaponType) {
return new ElfWeapon(weaponType);
return ELFARSENAL.get(weaponType);
}
}

public class OrcBlacksmith implements Blacksmith {
public Weapon manufactureWeapon(WeaponType weaponType) {
return new OrcWeapon(weaponType);
return ORCARSENAL.get(weaponType);
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,27 @@

package com.iluwatar.factory.method;

import java.util.HashMap;
import java.util.Map;

/**
*
* Concrete subclass for creating new objects.
*
*/
public class ElfBlacksmith implements Blacksmith {

private static Map<WeaponType, ElfWeapon> ELFARSENAL;
static {
ELFARSENAL= new HashMap<>(WeaponType.values().length);
for (WeaponType type : WeaponType.values()) {
ELFARSENAL.put(type, new ElfWeapon(type));
}
}

@Override
public Weapon manufactureWeapon(WeaponType weaponType) {
return new ElfWeapon(weaponType);
return ELFARSENAL.get(weaponType);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,26 @@

package com.iluwatar.factory.method;

import java.util.HashMap;
import java.util.Map;

/**
*
* Concrete subclass for creating new objects.
*
*/
public class OrcBlacksmith implements Blacksmith {

private static Map<WeaponType, OrcWeapon> ORCARSENAL;
static {
ORCARSENAL= new HashMap<>(WeaponType.values().length);
for (WeaponType type : WeaponType.values()) {
ORCARSENAL.put(type, new OrcWeapon(type));
}
}

@Override
public Weapon manufactureWeapon(WeaponType weaponType) {
return new OrcWeapon(weaponType);
return ORCARSENAL.get(weaponType);
}
}