|
3 | 3 | import com.iluwatar.Hero.HeroBuilder;
|
4 | 4 |
|
5 | 5 | /**
|
6 |
| - * |
7 |
| - * This is the Builder pattern variation as described by |
8 |
| - * Joshua Bloch in Effective Java 2nd Edition. |
9 |
| - * |
10 |
| - * We want to build Hero objects, but its construction |
11 |
| - * is complex because of the many parameters needed. To |
12 |
| - * aid the user we introduce HeroBuilder class. HeroBuilder |
13 |
| - * takes the minimum parameters to build Hero object in |
14 |
| - * its constructor. After that additional configuration |
15 |
| - * for the Hero object can be done using the fluent |
16 |
| - * HeroBuilder interface. When configuration is ready |
17 |
| - * the build method is called to receive the final Hero |
18 |
| - * object. |
| 6 | + * |
| 7 | + * This is the Builder pattern variation as described by Joshua Bloch in |
| 8 | + * Effective Java 2nd Edition. |
| 9 | + * |
| 10 | + * We want to build Hero objects, but its construction is complex because of the |
| 11 | + * many parameters needed. To aid the user we introduce HeroBuilder class. |
| 12 | + * HeroBuilder takes the minimum parameters to build Hero object in its |
| 13 | + * constructor. After that additional configuration for the Hero object can be |
| 14 | + * done using the fluent HeroBuilder interface. When configuration is ready the |
| 15 | + * build method is called to receive the final Hero object. |
19 | 16 | *
|
20 | 17 | */
|
21 |
| -public class App |
22 |
| -{ |
23 |
| - public static void main( String[] args ) |
24 |
| - { |
25 |
| - |
26 |
| - Hero mage = new HeroBuilder(Profession.MAGE, "Riobard") |
27 |
| - .withHairColor(HairColor.BLACK) |
28 |
| - .withWeapon(Weapon.DAGGER) |
29 |
| - .build(); |
30 |
| - System.out.println(mage); |
| 18 | +public class App { |
| 19 | + |
| 20 | + public static void main(String[] args) { |
| 21 | + |
| 22 | + Hero mage = new HeroBuilder(Profession.MAGE, "Riobard") |
| 23 | + .withHairColor(HairColor.BLACK) |
| 24 | + .withWeapon(Weapon.DAGGER) |
| 25 | + .build(); |
| 26 | + System.out.println(mage); |
| 27 | + |
| 28 | + Hero warrior = new HeroBuilder(Profession.WARRIOR, "Amberjill") |
| 29 | + .withHairColor(HairColor.BLOND) |
| 30 | + .withHairType(HairType.LONG_CURLY) |
| 31 | + .withArmor(Armor.CHAIN_MAIL) |
| 32 | + .withWeapon(Weapon.SWORD) |
| 33 | + .build(); |
| 34 | + System.out.println(warrior); |
31 | 35 |
|
32 |
| - Hero warrior = new HeroBuilder(Profession.WARRIOR, "Amberjill") |
33 |
| - .withHairColor(HairColor.BLOND) |
34 |
| - .withHairType(HairType.LONG_CURLY) |
35 |
| - .withArmor(Armor.CHAIN_MAIL) |
36 |
| - .withWeapon(Weapon.SWORD) |
37 |
| - .build(); |
38 |
| - System.out.println(warrior); |
| 36 | + Hero thief = new HeroBuilder(Profession.THIEF, "Desmond") |
| 37 | + .withHairType(HairType.BALD) |
| 38 | + .withWeapon(Weapon.BOW) |
| 39 | + .build(); |
| 40 | + System.out.println(thief); |
39 | 41 |
|
40 |
| - Hero thief = new HeroBuilder(Profession.THIEF, "Desmond") |
41 |
| - .withHairType(HairType.BALD) |
42 |
| - .withWeapon(Weapon.BOW) |
43 |
| - .build(); |
44 |
| - System.out.println(thief); |
45 |
| - |
46 | 42 | }
|
47 | 43 | }
|
0 commit comments