Made example App a bit easier to understand
This commit is contained in:
parent
f64ba22c64
commit
b5d4445d63
@ -52,14 +52,6 @@ public class App {
|
|||||||
setArmy(factory.createArmy());
|
setArmy(factory.createArmy());
|
||||||
}
|
}
|
||||||
|
|
||||||
ElfKingdomFactory getElfKingdomFactory() {
|
|
||||||
return new ElfKingdomFactory();
|
|
||||||
}
|
|
||||||
|
|
||||||
OrcKingdomFactory getOrcKingdomFactory() {
|
|
||||||
return new OrcKingdomFactory();
|
|
||||||
}
|
|
||||||
|
|
||||||
King getKing(final KingdomFactory factory) {
|
King getKing(final KingdomFactory factory) {
|
||||||
return factory.createKing();
|
return factory.createKing();
|
||||||
}
|
}
|
||||||
@ -107,17 +99,13 @@ public class App {
|
|||||||
App app = new App();
|
App app = new App();
|
||||||
|
|
||||||
System.out.println("Elf Kingdom");
|
System.out.println("Elf Kingdom");
|
||||||
KingdomFactory elfKingdomFactory;
|
app.createKingdom(new ElfKingdomFactory());
|
||||||
elfKingdomFactory = app.getElfKingdomFactory();
|
|
||||||
app.createKingdom(elfKingdomFactory);
|
|
||||||
System.out.println(app.getArmy().getDescription());
|
System.out.println(app.getArmy().getDescription());
|
||||||
System.out.println(app.getCastle().getDescription());
|
System.out.println(app.getCastle().getDescription());
|
||||||
System.out.println(app.getKing().getDescription());
|
System.out.println(app.getKing().getDescription());
|
||||||
|
|
||||||
System.out.println("\nOrc Kingdom");
|
System.out.println("\nOrc Kingdom");
|
||||||
KingdomFactory orcKingdomFactory;
|
app.createKingdom(new OrcKingdomFactory());
|
||||||
orcKingdomFactory = app.getOrcKingdomFactory();
|
|
||||||
app.createKingdom(orcKingdomFactory);
|
|
||||||
System.out.println(app.getArmy().getDescription());
|
System.out.println(app.getArmy().getDescription());
|
||||||
System.out.println(app.getCastle().getDescription());
|
System.out.println(app.getCastle().getDescription());
|
||||||
System.out.println(app.getKing().getDescription());
|
System.out.println(app.getKing().getDescription());
|
||||||
|
@ -36,8 +36,8 @@ public class AbstractFactoryTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
elfFactory = app.getElfKingdomFactory();
|
elfFactory = new ElfKingdomFactory();
|
||||||
orcFactory = app.getOrcKingdomFactory();
|
orcFactory = new OrcKingdomFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user