Builder

Intent

Separate the construction of a complex object from its representation so that the same construction process can create different representations.

Class diagram of the original GoF pattern

structure-GoF:builder

Improvement in MixJuice

Solved Problem(s)

Extensibility problem
Adding new methods to Builder and ConcreteBuilder classes is impossible without modifying the source code. (This problem is mentioned at p.100,line.32-p.101,line.4 in the GoF book.)

Used programming technique(s)

Method addition to Builder and ConcreteBuilder classes.

Consequences

Structure and pseudo code

structure:builder_sample1

module original {
 define abstract class Builder {
   define void buildPartA(){}
   define void buildPartB(){}
 }
 define class ConcreteBuilder extends Builder {
   void buildPartA(){...}
   void buildPartB(){...}
 }
 define class Director {
   Builder builder;
   define void construct(){
     builder.buildPartA();
     builder.buildPartB();
   }
 }
}
module extension extends original {
 class Builder {
   define void buildPartC(){}
 }
 define class ConcreteBuilder2 extends Builder {
   void buildPartA(){...}
   void buildPartB(){...}
   void buildPartC(){...}
 }
 class Director {
   void construct(){
     original();
     builder.buildPartC();
   }
 }
}

Another solution in MixJuice

Solved Problem(s)

Complexity problem
The class structure of the original GoF pattern is complicated.

Used programming technique(s)

Implementation selection for Builder.

Consequences

Structure and pseudo code

structure:builder_sample2

module builder {
  define class Builder {
    // This class has Director's function.
    define void construct() { ... }

    define void buildPartA() {}
    define void buildPartB() {}
    define void buildPartC() {}
  }
}

module builder.implementation1 extends builder {
  class Builder {
    void buildPartA() { ... }
    void buildPartB() { ... }
    void buildPartC() { ... }
  }
}

module builder.implementation2 extends builder {
  class Builder {
    void buildPartA() { ... }
    void buildPartB() { ... }
    void buildPartC() { ... }
  }
}

Akira TANAKA <akr@m17n.org>, Yuuji ICHISUGI <y-ichisugi@aist.go.jp>

Top