File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed
builder/src/main/java/com/iluwatar Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change 22
33import 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+ */
521public class App
622{
723 public static void main ( String [] args )
Original file line number Diff line number Diff line change 11package com .iluwatar ;
22
3+ /**
4+ *
5+ * The class with many parameters.
6+ *
7+ */
38public 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}
You can’t perform that action at this time.
0 commit comments