Evaluating Software Design Patterns
— the "Gang of Four" patterns implemented in Java 6

@Pattern(name="Builder", scope=Object, purpose=Creational, participants={"Builder","ConcreteBuilder","Director","Product"})

Package dk.rode.thesis.builder

Implementations and examples of the Builder design pattern [Gamma95, p.97].

See:
          Description

Interface Summary
ComparableExpressionBuilder<E extends Comparable<? super E>> A comparable expression builder construct various Expression types having a Comparable bound on the value produced by the constructed expressions and/or on the expression operands used.
ExpressionBuilder<E> An expression builder construct various Expression types having no bounds on the values produced by the constructed expressions.
 

Class Summary
AbstractExpressionBuilder<E> An abstract expression builder implements the basic traits of the ExpressionBuilder interface, while ensuring that the constructed terminal expressions will all manipulate the same sequence instance.
CountingComparableExpressionBuilder<E extends Comparable<? super E>> A counting comparable expression builder performs the same functionality as a standard expression builder, but also registers the number of times each expression type is created based on expression names.
CountingExpressionBuilder<E> A counting expression builder performs the same functionality as a standard expression builder, but also registers the number of times each expression type is created based on expression names.
Main Builder tests.
StandardComparableExpressionBuilder<E extends Comparable<? super E>> A comparable expression builder construct various Expression types having a Comparable bound on the value produced by the constructed expressions and on the expression operands used.
StandardExpressionBuilder<E> A standard expression builder construct various Expression types having no bounds on the values produced by constructed expressions.
TypedComparableExpressionBuilder<E extends Comparable<? super E>> A typed comparable expression builder construct various TypedExpression types having a Comparable bound on the value produced by the constructed expressions and on the expression operands used.
TypedExpressionBuilder<E> A typed expression builder builds typed expressions.
TypedFlowExpression<E> A typed flow expression represents one or more expressions to be evaluated in order, one at a time, where the type of value the evaluation of the expressions produces associated with it at runtime.
 

Package dk.rode.thesis.builder Description

Implementations and examples of the Builder design pattern [Gamma95, p.97].

Intent:

Here, the Builder participant is represented by the ExpressionBuilder and ComparableExpressionBuilder types, and the ConcreteBuilder participant by any implementation of either of them. The builders build Expression objects, and the Expression interface thus corresponds to the Product participant. The overall constructed root expression can be fetched using the ExpressionBuilder.getRootExpression() method.

Six concrete builders are provided, namely the StandardExpressionBuilder, StandardComparableExpressionBuilder, CountingExpressionBuilder, CountingComparableExpressionBuilder, TypedExpressionBuilder, and TypedComparableExpressionBuilder, classes. The middle two performs the same functionality as the first two, respectively, but also keeps track of the number of constructed expressions, inspired by the Gamma et al. example in [Gamma95, p.104]. The last two creates TypedExpression instances, but uses composition to allow another builder to perform the actual creation.

Finally, the Director participant is represented by the Main class, which uses the builders to construct Expression objects.

UML Class Diagram:

Implementation notes:
Overall idea based on the example from [Gamma95, p.189].

The TypedExpressionBuilder illustrates good usage of covariant return types, but also the problems that can be associated with it (see the class documentation).

Author:
Gunni Rode / rode.dk

Gunni Rode / rode.dk

Feel free to use and/or modify the Java 6 source code developed for this thesis AT YOUR OWN RISK, but note that the source code comes WITHOUT ANY — and I do mean WITHOUT ANY — form of warranty WHAT SO EVER!

The original thesis and source code are available at rode.dk/thesis.