#107 JavaDoc improvements for Abstract Factory example
This commit is contained in:
parent
0d2df99013
commit
fd85a2f848
@ -1,29 +1,37 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* The essence of the Abstract Factory pattern is a factory interface
|
||||
* (KingdomFactory) and its implementations (ElfKingdomFactory,
|
||||
* OrcKingdomFactory).
|
||||
*
|
||||
* The example uses both concrete implementations to create a king, a castle and
|
||||
* an army.
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) {
|
||||
createKingdom(new ElfKingdomFactory());
|
||||
createKingdom(new OrcKingdomFactory());
|
||||
}
|
||||
|
||||
public static void createKingdom(KingdomFactory factory) {
|
||||
King king = factory.createKing();
|
||||
Castle castle = factory.createCastle();
|
||||
Army army = factory.createArmy();
|
||||
System.out.println("The kingdom was created.");
|
||||
System.out.println(king);
|
||||
System.out.println(castle);
|
||||
System.out.println(army);
|
||||
}
|
||||
}
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* The essence of the Abstract Factory pattern is a factory interface
|
||||
* ({@link KingdomFactory}) and its implementations ({@link ElfKingdomFactory},
|
||||
* {@link OrcKingdomFactory}).
|
||||
* <p>
|
||||
* The example uses both concrete implementations to create a king, a castle and
|
||||
* an army.
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
* @param args command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
createKingdom(new ElfKingdomFactory());
|
||||
createKingdom(new OrcKingdomFactory());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates kingdom
|
||||
* @param factory
|
||||
*/
|
||||
public static void createKingdom(KingdomFactory factory) {
|
||||
King king = factory.createKing();
|
||||
Castle castle = factory.createCastle();
|
||||
Army army = factory.createArmy();
|
||||
System.out.println("The kingdom was created.");
|
||||
System.out.println(king);
|
||||
System.out.println(castle);
|
||||
System.out.println(army);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
public interface Army {
|
||||
|
||||
}
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* Army interface
|
||||
*
|
||||
*/
|
||||
public interface Army {
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
public interface Castle {
|
||||
|
||||
}
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* Castle interface
|
||||
*
|
||||
*/
|
||||
public interface Castle {
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,15 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
public class ElfArmy implements Army {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "This is the Elven Army!";
|
||||
}
|
||||
|
||||
}
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* ElfArmy
|
||||
*
|
||||
*/
|
||||
public class ElfArmy implements Army {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "This is the Elven Army!";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,15 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
public class ElfCastle implements Castle {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "This is the Elven castle!";
|
||||
}
|
||||
|
||||
}
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* ElfCastle
|
||||
*
|
||||
*/
|
||||
public class ElfCastle implements Castle {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "This is the Elven castle!";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,15 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
public class ElfKing implements King {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "This is the Elven king!";
|
||||
}
|
||||
|
||||
}
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* ElfKing
|
||||
*
|
||||
*/
|
||||
public class ElfKing implements King {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "This is the Elven king!";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,22 +1,22 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* Concrete factory.
|
||||
*
|
||||
*/
|
||||
public class ElfKingdomFactory implements KingdomFactory {
|
||||
|
||||
public Castle createCastle() {
|
||||
return new ElfCastle();
|
||||
}
|
||||
|
||||
public King createKing() {
|
||||
return new ElfKing();
|
||||
}
|
||||
|
||||
public Army createArmy() {
|
||||
return new ElfArmy();
|
||||
}
|
||||
|
||||
}
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* ElfKingdomFactory concrete factory.
|
||||
*
|
||||
*/
|
||||
public class ElfKingdomFactory implements KingdomFactory {
|
||||
|
||||
public Castle createCastle() {
|
||||
return new ElfCastle();
|
||||
}
|
||||
|
||||
public King createKing() {
|
||||
return new ElfKing();
|
||||
}
|
||||
|
||||
public Army createArmy() {
|
||||
return new ElfArmy();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
public interface King {
|
||||
|
||||
}
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* King interface
|
||||
*
|
||||
*/
|
||||
public interface King {
|
||||
|
||||
}
|
||||
|
@ -1,16 +1,16 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* The factory interface.
|
||||
*
|
||||
*/
|
||||
public interface KingdomFactory {
|
||||
|
||||
Castle createCastle();
|
||||
|
||||
King createKing();
|
||||
|
||||
Army createArmy();
|
||||
|
||||
}
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* KingdomFactory factory interface.
|
||||
*
|
||||
*/
|
||||
public interface KingdomFactory {
|
||||
|
||||
Castle createCastle();
|
||||
|
||||
King createKing();
|
||||
|
||||
Army createArmy();
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,15 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
public class OrcArmy implements Army {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "This is the Orcish Army!";
|
||||
}
|
||||
|
||||
}
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* OrcArmy
|
||||
*
|
||||
*/
|
||||
public class OrcArmy implements Army {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "This is the Orcish Army!";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,15 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
public class OrcCastle implements Castle {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "This is the Orcish castle!";
|
||||
}
|
||||
|
||||
}
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* OrcCastle
|
||||
*
|
||||
*/
|
||||
public class OrcCastle implements Castle {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "This is the Orcish castle!";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,15 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
public class OrcKing implements King {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "This is the Orc king!";
|
||||
}
|
||||
|
||||
}
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* OrcKing
|
||||
*
|
||||
*/
|
||||
public class OrcKing implements King {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "This is the Orc king!";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,22 +1,22 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* Concrete factory.
|
||||
*
|
||||
*/
|
||||
public class OrcKingdomFactory implements KingdomFactory {
|
||||
|
||||
public Castle createCastle() {
|
||||
return new OrcCastle();
|
||||
}
|
||||
|
||||
public King createKing() {
|
||||
return new OrcKing();
|
||||
}
|
||||
|
||||
public Army createArmy() {
|
||||
return new OrcArmy();
|
||||
}
|
||||
|
||||
}
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* OrcKingdomFactory concrete factory.
|
||||
*
|
||||
*/
|
||||
public class OrcKingdomFactory implements KingdomFactory {
|
||||
|
||||
public Castle createCastle() {
|
||||
return new OrcCastle();
|
||||
}
|
||||
|
||||
public King createKing() {
|
||||
return new OrcKing();
|
||||
}
|
||||
|
||||
public Army createArmy() {
|
||||
return new OrcArmy();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user