提交 427df4e1 编写于 作者: I Ilkka Seppala

Added comments for Builder example.

上级 5aead88e
...@@ -2,6 +2,22 @@ package com.iluwatar; ...@@ -2,6 +2,22 @@ package com.iluwatar;
import com.iluwatar.Hero.HeroBuilder; import com.iluwatar.Hero.HeroBuilder;
/**
*
* This is the Builder pattern variation as described by
* Joshua Bloch in Effective Java 2nd Edition.
*
* We want to build Hero objects, but its construction
* is complex because of the many parameters needed. To
* aid the user we introduce HeroBuilder class. HeroBuilder
* takes the minimum parameters to build Hero object in
* its constructor. After that additional configuration
* for the Hero object can be done using the fluent
* HeroBuilder interface. When configuration is ready
* the build method is called to receive the final Hero
* object.
*
*/
public class App public class App
{ {
public static void main( String[] args ) public static void main( String[] args )
......
package com.iluwatar; package com.iluwatar;
/**
*
* The class with many parameters.
*
*/
public class Hero { public class Hero {
private final Profession profession; private final Profession profession;
...@@ -72,7 +77,12 @@ public class Hero { ...@@ -72,7 +77,12 @@ public class Hero {
this.weapon = builder.weapon; this.weapon = builder.weapon;
this.armor = builder.armor; this.armor = builder.armor;
} }
/**
*
* The builder class.
*
*/
public static class HeroBuilder { public static class HeroBuilder {
private final Profession profession; private final Profession profession;
...@@ -113,7 +123,5 @@ public class Hero { ...@@ -113,7 +123,5 @@ public class Hero {
public Hero build() { public Hero build() {
return new Hero(this); return new Hero(this);
} }
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册