2014-08-10 10:07:38 +03:00
|
|
|
package com.iluwatar;
|
|
|
|
|
2014-08-31 08:29:50 +03:00
|
|
|
/**
|
2014-10-07 16:23:37 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2014-08-31 08:29:50 +03:00
|
|
|
*
|
|
|
|
*/
|
2014-10-07 16:23:37 +01:00
|
|
|
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);
|
2014-08-10 10:07:38 +03:00
|
|
|
}
|
|
|
|
}
|