#108 Consistent package naming throughout the examples
This commit is contained in:
		| @@ -1,28 +1,28 @@ | ||||
| package com.iluwatar.factorymethod; | ||||
| 
 | ||||
| /** | ||||
|  *  | ||||
|  * 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; | ||||
| 
 | ||||
| 		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); | ||||
| 	} | ||||
| } | ||||
| package com.iluwatar.factory.method; | ||||
| 
 | ||||
| /** | ||||
|  *  | ||||
|  * 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; | ||||
| 
 | ||||
| 		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); | ||||
| 	} | ||||
| } | ||||
| @@ -1,12 +1,12 @@ | ||||
| package com.iluwatar.factorymethod; | ||||
| 
 | ||||
| /** | ||||
|  *  | ||||
|  * The interface containing method for producing objects. | ||||
|  *  | ||||
|  */ | ||||
| public interface Blacksmith { | ||||
| 
 | ||||
| 	Weapon manufactureWeapon(WeaponType weaponType); | ||||
| 
 | ||||
| } | ||||
| package com.iluwatar.factory.method; | ||||
| 
 | ||||
| /** | ||||
|  *  | ||||
|  * The interface containing method for producing objects. | ||||
|  *  | ||||
|  */ | ||||
| public interface Blacksmith { | ||||
| 
 | ||||
| 	Weapon manufactureWeapon(WeaponType weaponType); | ||||
| 
 | ||||
| } | ||||
| @@ -1,14 +1,14 @@ | ||||
| package com.iluwatar.factorymethod; | ||||
| 
 | ||||
| /** | ||||
|  *  | ||||
|  * Concrete subclass for creating new objects. | ||||
|  *  | ||||
|  */ | ||||
| public class ElfBlacksmith implements Blacksmith { | ||||
| 
 | ||||
| 	public Weapon manufactureWeapon(WeaponType weaponType) { | ||||
| 		return new ElfWeapon(weaponType); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| package com.iluwatar.factory.method; | ||||
| 
 | ||||
| /** | ||||
|  *  | ||||
|  * Concrete subclass for creating new objects. | ||||
|  *  | ||||
|  */ | ||||
| public class ElfBlacksmith implements Blacksmith { | ||||
| 
 | ||||
| 	public Weapon manufactureWeapon(WeaponType weaponType) { | ||||
| 		return new ElfWeapon(weaponType); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| @@ -1,16 +1,16 @@ | ||||
| package com.iluwatar.factorymethod; | ||||
| 
 | ||||
| public class ElfWeapon implements Weapon { | ||||
| 
 | ||||
| 	private WeaponType weaponType; | ||||
| 
 | ||||
| 	public ElfWeapon(WeaponType weaponType) { | ||||
| 		this.weaponType = weaponType; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString() { | ||||
| 		return "Elven " + weaponType; | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| package com.iluwatar.factory.method; | ||||
| 
 | ||||
| public class ElfWeapon implements Weapon { | ||||
| 
 | ||||
| 	private WeaponType weaponType; | ||||
| 
 | ||||
| 	public ElfWeapon(WeaponType weaponType) { | ||||
| 		this.weaponType = weaponType; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString() { | ||||
| 		return "Elven " + weaponType; | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| @@ -1,14 +1,14 @@ | ||||
| package com.iluwatar.factorymethod; | ||||
| 
 | ||||
| /** | ||||
|  *  | ||||
|  * Concrete subclass for creating new objects. | ||||
|  *  | ||||
|  */ | ||||
| public class OrcBlacksmith implements Blacksmith { | ||||
| 
 | ||||
| 	public Weapon manufactureWeapon(WeaponType weaponType) { | ||||
| 		return new OrcWeapon(weaponType); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| package com.iluwatar.factory.method; | ||||
| 
 | ||||
| /** | ||||
|  *  | ||||
|  * Concrete subclass for creating new objects. | ||||
|  *  | ||||
|  */ | ||||
| public class OrcBlacksmith implements Blacksmith { | ||||
| 
 | ||||
| 	public Weapon manufactureWeapon(WeaponType weaponType) { | ||||
| 		return new OrcWeapon(weaponType); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| @@ -1,16 +1,16 @@ | ||||
| package com.iluwatar.factorymethod; | ||||
| 
 | ||||
| public class OrcWeapon implements Weapon { | ||||
| 
 | ||||
| 	private WeaponType weaponType; | ||||
| 
 | ||||
| 	public OrcWeapon(WeaponType weaponType) { | ||||
| 		this.weaponType = weaponType; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString() { | ||||
| 		return "Orcish " + weaponType; | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| package com.iluwatar.factory.method; | ||||
| 
 | ||||
| public class OrcWeapon implements Weapon { | ||||
| 
 | ||||
| 	private WeaponType weaponType; | ||||
| 
 | ||||
| 	public OrcWeapon(WeaponType weaponType) { | ||||
| 		this.weaponType = weaponType; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString() { | ||||
| 		return "Orcish " + weaponType; | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| @@ -0,0 +1,5 @@ | ||||
| package com.iluwatar.factory.method; | ||||
|  | ||||
| public interface Weapon { | ||||
|  | ||||
| } | ||||
| @@ -1,17 +1,17 @@ | ||||
| package com.iluwatar.factorymethod; | ||||
| 
 | ||||
| public enum WeaponType { | ||||
| 
 | ||||
| 	SHORT_SWORD("short sword"), SPEAR("spear"), AXE("axe"), UNDEFINED(""); | ||||
| 
 | ||||
|     private String title; | ||||
| 
 | ||||
|     WeaponType(String title) { | ||||
|         this.title = title; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
| 	public String toString() { | ||||
| 		return title; | ||||
| 	} | ||||
| } | ||||
| package com.iluwatar.factory.method; | ||||
| 
 | ||||
| public enum WeaponType { | ||||
| 
 | ||||
| 	SHORT_SWORD("short sword"), SPEAR("spear"), AXE("axe"), UNDEFINED(""); | ||||
| 
 | ||||
|     private String title; | ||||
| 
 | ||||
|     WeaponType(String title) { | ||||
|         this.title = title; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
| 	public String toString() { | ||||
| 		return title; | ||||
| 	} | ||||
| } | ||||
| @@ -1,5 +0,0 @@ | ||||
| package com.iluwatar.factorymethod; | ||||
|  | ||||
| public interface Weapon { | ||||
|  | ||||
| } | ||||
| @@ -1,14 +1,14 @@ | ||||
| package com.iluwatar.factorymethod; | ||||
| 
 | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| import com.iluwatar.factorymethod.App; | ||||
| 
 | ||||
| public class AppTest { | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void test() { | ||||
| 		String[] args = {}; | ||||
| 		App.main(args); | ||||
| 	} | ||||
| } | ||||
| package com.iluwatar.factory.method; | ||||
| 
 | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| import com.iluwatar.factory.method.App; | ||||
| 
 | ||||
| public class AppTest { | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void test() { | ||||
| 		String[] args = {}; | ||||
| 		App.main(args); | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user