Formatted all files to the same standard
This commit is contained in:
@ -1,28 +1,28 @@
|
||||
package com.iluwatar;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* In Factory Method we have an interface (Blacksmith) with a method for
|
||||
* creating objects (manufactureWeapon). The concrete subclasses (OrcBlacksmith,
|
||||
* ElfBlacksmith) then override the method to produce objects of their liking.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Blacksmith blacksmith;
|
||||
Weapon weapon;
|
||||
public static void main(String[] args) {
|
||||
Blacksmith blacksmith;
|
||||
Weapon weapon;
|
||||
|
||||
blacksmith = new OrcBlacksmith();
|
||||
weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
|
||||
System.out.println(weapon);
|
||||
weapon = blacksmith.manufactureWeapon(WeaponType.AXE);
|
||||
System.out.println(weapon);
|
||||
blacksmith = new OrcBlacksmith();
|
||||
weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
|
||||
System.out.println(weapon);
|
||||
weapon = blacksmith.manufactureWeapon(WeaponType.AXE);
|
||||
System.out.println(weapon);
|
||||
|
||||
blacksmith = new ElfBlacksmith();
|
||||
weapon = blacksmith.manufactureWeapon(WeaponType.SHORT_SWORD);
|
||||
System.out.println(weapon);
|
||||
weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
|
||||
System.out.println(weapon);
|
||||
}
|
||||
blacksmith = new ElfBlacksmith();
|
||||
weapon = blacksmith.manufactureWeapon(WeaponType.SHORT_SWORD);
|
||||
System.out.println(weapon);
|
||||
weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
|
||||
System.out.println(weapon);
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,10 @@ package com.iluwatar;
|
||||
/**
|
||||
*
|
||||
* The interface containing method for producing objects.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface Blacksmith {
|
||||
|
||||
Weapon manufactureWeapon(WeaponType weaponType);
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package com.iluwatar;
|
||||
/**
|
||||
*
|
||||
* Concrete subclass for creating new objects.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ElfBlacksmith implements Blacksmith {
|
||||
|
||||
|
@ -12,5 +12,5 @@ public class ElfWeapon implements Weapon {
|
||||
public String toString() {
|
||||
return "Elven " + weaponType;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package com.iluwatar;
|
||||
/**
|
||||
*
|
||||
* Concrete subclass for creating new objects.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class OrcBlacksmith implements Blacksmith {
|
||||
|
||||
|
@ -12,5 +12,5 @@ public class OrcWeapon implements Weapon {
|
||||
public String toString() {
|
||||
return "Orcish " + weaponType;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -7,13 +7,18 @@ public enum WeaponType {
|
||||
@Override
|
||||
public String toString() {
|
||||
String s = "";
|
||||
switch(this) {
|
||||
case SHORT_SWORD: s = "short sword"; break;
|
||||
case SPEAR: s = "spear"; break;
|
||||
case AXE: s = "axe"; break;
|
||||
switch (this) {
|
||||
case SHORT_SWORD:
|
||||
s = "short sword";
|
||||
break;
|
||||
case SPEAR:
|
||||
s = "spear";
|
||||
break;
|
||||
case AXE:
|
||||
s = "axe";
|
||||
break;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user