task: Explanations and grammar fixes for all the GoF patterns (#1791)
* Grammatical fixes to command pattern * Update bridge pattern readme * Fixes to builder pattern grammar * Update chain of responsibility * Improvements to the composite example * Fixes to headings * Minor updates to decorator pattern * Update facade * Update factory example * Update factory method * Update flyweight * Interpreter explanation * Update iterator readme * Add explanation for mediator pattern * Grammatical fixes to memento * Grammar fixes for observer * Update explanation for the prototype pattern * Proxy pattern grammar fixes * Update singleton * Grammar fixes to state pattern * Grammar fixes for strategy * Grammar fixes, template method * Grammar fixes for visitor * Fix typo
This commit is contained in:
@@ -26,7 +26,7 @@ package com.iluwatar.factory.method;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* The Factory Method is a creational design pattern which uses factory methods to deal with the
|
||||
* The Factory Method is a creational design pattern that uses factory methods to deal with the
|
||||
* 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
|
||||
* and implemented by child classes, or implemented in a base class and optionally overridden by
|
||||
@@ -41,39 +41,22 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Slf4j
|
||||
public class App {
|
||||
|
||||
private final Blacksmith blacksmith;
|
||||
|
||||
/**
|
||||
* Creates an instance of <code>App</code> which will use <code>blacksmith</code> to manufacture
|
||||
* the weapons for war.
|
||||
* <code>App</code> is unaware which concrete implementation of {@link Blacksmith} it is using.
|
||||
* The decision of which blacksmith implementation to use may depend on configuration, or
|
||||
* the type of rival in war.
|
||||
* @param blacksmith a non-null implementation of blacksmith
|
||||
*/
|
||||
public App(Blacksmith blacksmith) {
|
||||
this.blacksmith = blacksmith;
|
||||
}
|
||||
|
||||
/**
|
||||
* Program entry point.
|
||||
*
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// Lets go to war with Orc weapons
|
||||
var app = new App(new OrcBlacksmith());
|
||||
app.manufactureWeapons();
|
||||
|
||||
// Lets go to war with Elf weapons
|
||||
app = new App(new ElfBlacksmith());
|
||||
app.manufactureWeapons();
|
||||
}
|
||||
|
||||
private void manufactureWeapons() {
|
||||
var weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
|
||||
LOGGER.info(weapon.toString());
|
||||
Blacksmith blacksmith = new OrcBlacksmith();
|
||||
Weapon weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
|
||||
LOGGER.info("{} manufactured {}", blacksmith, weapon);
|
||||
weapon = blacksmith.manufactureWeapon(WeaponType.AXE);
|
||||
LOGGER.info(weapon.toString());
|
||||
LOGGER.info("{} manufactured {}", blacksmith, weapon);
|
||||
|
||||
blacksmith = new ElfBlacksmith();
|
||||
weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
|
||||
LOGGER.info("{} manufactured {}", blacksmith, weapon);
|
||||
weapon = blacksmith.manufactureWeapon(WeaponType.AXE);
|
||||
LOGGER.info("{} manufactured {}", blacksmith, weapon);
|
||||
}
|
||||
}
|
||||
|
@@ -44,4 +44,8 @@ public class ElfBlacksmith implements Blacksmith {
|
||||
return ELFARSENAL.get(weaponType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "The elf blacksmith";
|
||||
}
|
||||
}
|
||||
|
@@ -37,6 +37,6 @@ public class ElfWeapon implements Weapon {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Elven " + weaponType;
|
||||
return "an elven " + weaponType;
|
||||
}
|
||||
}
|
||||
|
@@ -43,4 +43,9 @@ public class OrcBlacksmith implements Blacksmith {
|
||||
public Weapon manufactureWeapon(WeaponType weaponType) {
|
||||
return ORCARSENAL.get(weaponType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "The orc blacksmith";
|
||||
}
|
||||
}
|
||||
|
@@ -37,6 +37,6 @@ public class OrcWeapon implements Weapon {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Orcish " + weaponType;
|
||||
return "an orcish " + weaponType;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user