Skip to content

Commit 427df4e

Browse files
committed
Added comments for Builder example.
1 parent 5aead88 commit 427df4e

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

builder/src/main/java/com/iluwatar/App.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22

33
import com.iluwatar.Hero.HeroBuilder;
44

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.
19+
*
20+
*/
521
public class App
622
{
723
public static void main( String[] args )

builder/src/main/java/com/iluwatar/Hero.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.iluwatar;
22

3+
/**
4+
*
5+
* The class with many parameters.
6+
*
7+
*/
38
public class Hero {
49

510
private final Profession profession;
@@ -72,7 +77,12 @@ private Hero(HeroBuilder builder) {
7277
this.weapon = builder.weapon;
7378
this.armor = builder.armor;
7479
}
75-
80+
81+
/**
82+
*
83+
* The builder class.
84+
*
85+
*/
7686
public static class HeroBuilder {
7787

7888
private final Profession profession;
@@ -113,7 +123,5 @@ public HeroBuilder withWeapon(Weapon weapon) {
113123
public Hero build() {
114124
return new Hero(this);
115125
}
116-
117126
}
118-
119127
}

0 commit comments

Comments
 (0)