Reformat rest of the design patterns - Issue #224

This commit is contained in:
Ankur Kaushal
2015-11-01 21:29:13 -05:00
parent 449340bd2b
commit 306b1f3d31
337 changed files with 6744 additions and 6851 deletions

View File

@ -2,39 +2,39 @@ package com.iluwatar.factory.method;
/**
*
* The Factory Method is a creational design pattern which 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 derived classes—rather than by calling a
* constructor.
* The Factory Method is a creational design pattern which 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
* derived classes—rather than by calling a constructor.
* <p>
* In this Factory Method example we have an interface ({@link Blacksmith}) with a method for
* creating objects ({@link Blacksmith#manufactureWeapon}). The concrete subclasses
* ({@link OrcBlacksmith}, {@link ElfBlacksmith}) then override the method to produce
* objects of their liking.
* creating objects ({@link Blacksmith#manufactureWeapon}). The concrete subclasses (
* {@link OrcBlacksmith}, {@link ElfBlacksmith}) then override the method to produce objects of
* their liking.
*
*/
public class App {
/**
* Program entry point
* @param args command line args
*/
public static void main(String[] args) {
Blacksmith blacksmith;
Weapon weapon;
/**
* Program entry point
*
* @param args command line args
*/
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);
}
}

View File

@ -7,6 +7,6 @@ package com.iluwatar.factory.method;
*/
public interface Blacksmith {
Weapon manufactureWeapon(WeaponType weaponType);
Weapon manufactureWeapon(WeaponType weaponType);
}

View File

@ -7,8 +7,8 @@ package com.iluwatar.factory.method;
*/
public class ElfBlacksmith implements Blacksmith {
public Weapon manufactureWeapon(WeaponType weaponType) {
return new ElfWeapon(weaponType);
}
public Weapon manufactureWeapon(WeaponType weaponType) {
return new ElfWeapon(weaponType);
}
}

View File

@ -7,15 +7,14 @@ package com.iluwatar.factory.method;
*/
public class ElfWeapon implements Weapon {
private WeaponType weaponType;
private WeaponType weaponType;
public ElfWeapon(WeaponType weaponType) {
this.weaponType = weaponType;
}
@Override
public String toString() {
return "Elven " + weaponType;
}
public ElfWeapon(WeaponType weaponType) {
this.weaponType = weaponType;
}
@Override
public String toString() {
return "Elven " + weaponType;
}
}

View File

@ -7,8 +7,7 @@ package com.iluwatar.factory.method;
*/
public class OrcBlacksmith implements Blacksmith {
public Weapon manufactureWeapon(WeaponType weaponType) {
return new OrcWeapon(weaponType);
}
public Weapon manufactureWeapon(WeaponType weaponType) {
return new OrcWeapon(weaponType);
}
}

View File

@ -7,15 +7,14 @@ package com.iluwatar.factory.method;
*/
public class OrcWeapon implements Weapon {
private WeaponType weaponType;
private WeaponType weaponType;
public OrcWeapon(WeaponType weaponType) {
this.weaponType = weaponType;
}
@Override
public String toString() {
return "Orcish " + weaponType;
}
public OrcWeapon(WeaponType weaponType) {
this.weaponType = weaponType;
}
@Override
public String toString() {
return "Orcish " + weaponType;
}
}

View File

@ -7,16 +7,16 @@ package com.iluwatar.factory.method;
*/
public enum WeaponType {
SHORT_SWORD("short sword"), SPEAR("spear"), AXE("axe"), UNDEFINED("");
SHORT_SWORD("short sword"), SPEAR("spear"), AXE("axe"), UNDEFINED("");
private String title;
private String title;
WeaponType(String title) {
this.title = title;
}
WeaponType(String title) {
this.title = title;
}
@Override
public String toString() {
return title;
}
@Override
public String toString() {
return title;
}
}

View File

@ -11,9 +11,9 @@ import com.iluwatar.factory.method.App;
*/
public class AppTest {
@Test
public void test() {
String[] args = {};
App.main(args);
}
@Test
public void test() {
String[] args = {};
App.main(args);
}
}