|
1 | | -package com.iluwatar.prototype; |
2 | | - |
3 | | -/** |
4 | | - * |
5 | | - * In Prototype we have a factory class (HeroFactoryImpl) producing objects by |
6 | | - * cloning existing ones. In this example the factory's prototype objects are |
7 | | - * given as constructor parameters. |
8 | | - * |
9 | | - */ |
10 | | -public class App { |
11 | | - |
12 | | - public static void main(String[] args) { |
13 | | - HeroFactory factory; |
14 | | - Mage mage; |
15 | | - Warlord warlord; |
16 | | - Beast beast; |
17 | | - |
18 | | - factory = new HeroFactoryImpl(new ElfMage(), new ElfWarlord(), |
19 | | - new ElfBeast()); |
20 | | - mage = factory.createMage(); |
21 | | - warlord = factory.createWarlord(); |
22 | | - beast = factory.createBeast(); |
23 | | - System.out.println(mage); |
24 | | - System.out.println(warlord); |
25 | | - System.out.println(beast); |
26 | | - |
27 | | - factory = new HeroFactoryImpl(new OrcMage(), new OrcWarlord(), |
28 | | - new OrcBeast()); |
29 | | - mage = factory.createMage(); |
30 | | - warlord = factory.createWarlord(); |
31 | | - beast = factory.createBeast(); |
32 | | - System.out.println(mage); |
33 | | - System.out.println(warlord); |
34 | | - System.out.println(beast); |
35 | | - } |
36 | | -} |
| 1 | +package com.iluwatar.prototype; |
| 2 | + |
| 3 | +/** |
| 4 | + * |
| 5 | + * In Prototype we have a factory class ({@link HeroFactoryImpl}) producing objects by |
| 6 | + * cloning the existing ones. In this example the factory's prototype objects are |
| 7 | + * given as constructor parameters. |
| 8 | + * |
| 9 | + */ |
| 10 | +public class App { |
| 11 | + |
| 12 | + /** |
| 13 | + * Program entry point |
| 14 | + * @param args command line args |
| 15 | + */ |
| 16 | + public static void main(String[] args) { |
| 17 | + HeroFactory factory; |
| 18 | + Mage mage; |
| 19 | + Warlord warlord; |
| 20 | + Beast beast; |
| 21 | + |
| 22 | + factory = new HeroFactoryImpl(new ElfMage(), new ElfWarlord(), |
| 23 | + new ElfBeast()); |
| 24 | + mage = factory.createMage(); |
| 25 | + warlord = factory.createWarlord(); |
| 26 | + beast = factory.createBeast(); |
| 27 | + System.out.println(mage); |
| 28 | + System.out.println(warlord); |
| 29 | + System.out.println(beast); |
| 30 | + |
| 31 | + factory = new HeroFactoryImpl(new OrcMage(), new OrcWarlord(), |
| 32 | + new OrcBeast()); |
| 33 | + mage = factory.createMage(); |
| 34 | + warlord = factory.createWarlord(); |
| 35 | + beast = factory.createBeast(); |
| 36 | + System.out.println(mage); |
| 37 | + System.out.println(warlord); |
| 38 | + System.out.println(beast); |
| 39 | + } |
| 40 | +} |
0 commit comments