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