Builder

Description

Delegates the task of building a product from its parts to a separate class, allowing different products to be built and the products to be built in different ways.
More info

Profile

UML profile of design pattern

Profile download (Rational Rose model)

OCL Constraints

context Builder
inv: self.isRoot implies self.isAbstract

inv: self.isAbstract implies (self.specialization->size() > 0 and
self.specialization->forAll (c | c.child.oclIsKindOf (Builder)))

inv: not self.isAbstract implies (self.createDep->size() > 0 and
self.getResultOp->size() > 0)

context aDirectorBuilder
inv: self.dBB.isNavigable and not self.dBD.isNavigable and
self.dBD.aggregation = AggregationKind::aggregate
	

Explanation of Profile

  1. A director class has operations the client uses to build different variations of a product.
  2. An abstract builder class defines operations that are used to build a product from its parts.
  3. The director has a unidirectional aggregate association with the abstract builder.
  4. The builder hierarchy must have some concrete builder classes, which provide an operation to return the products they build.
  5. Each concrete builder creates an instance of a build product.

Correct Instance

correct design pattern instance

Incorrect Instance

incorrect design pattern instance

The ReportBuilder and ResumeBuilder classes should define their own <<GetResultOp>> operation, whereas the DocumentBuilder class should not. The DocumentBuilder class is not abstract.

Tool Output

output of tool