From 427df4e1655ee9fa7413c09e2a88e8c3c38eef25 Mon Sep 17 00:00:00 2001 From: Ilkka Seppala Date: Sun, 31 Aug 2014 00:33:09 +0300 Subject: [PATCH] Added comments for Builder example. --- builder/src/main/java/com/iluwatar/App.java | 16 ++++++++++++++++ builder/src/main/java/com/iluwatar/Hero.java | 14 +++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/builder/src/main/java/com/iluwatar/App.java b/builder/src/main/java/com/iluwatar/App.java index 5d455e95d..1eea20c10 100644 --- a/builder/src/main/java/com/iluwatar/App.java +++ b/builder/src/main/java/com/iluwatar/App.java @@ -2,6 +2,22 @@ package com.iluwatar; 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 static void main( String[] args ) diff --git a/builder/src/main/java/com/iluwatar/Hero.java b/builder/src/main/java/com/iluwatar/Hero.java index 1cc8f16df..e728fab7a 100644 --- a/builder/src/main/java/com/iluwatar/Hero.java +++ b/builder/src/main/java/com/iluwatar/Hero.java @@ -1,5 +1,10 @@ package com.iluwatar; +/** + * + * The class with many parameters. + * + */ public class Hero { private final Profession profession; @@ -72,7 +77,12 @@ public class Hero { this.weapon = builder.weapon; this.armor = builder.armor; } - + + /** + * + * The builder class. + * + */ public static class HeroBuilder { private final Profession profession; @@ -113,7 +123,5 @@ public class Hero { public Hero build() { return new Hero(this); } - } - } -- GitLab