Showing posts with label design. Show all posts
Showing posts with label design. Show all posts

Saturday, March 27, 2010

C# implementation of Builder pattern

The builder pattern Separates the construction of a complex object from its representation.

The players in this pattern are:
1. Product (Room)
Represents the complex object which includes many classes(parts)
2. Builder (RoomBuilder)
Specifies an abstract class or an interface for creating parts of a Product object
3. ConcreteBuilder (WoodBuilder, GlassBuilder)
  • Constructs parts of the product by implementing the Builder class/interface
  • provides a way for retrieving the product
4. Director (House)
Constructs an object (room) using the Builder class/interface

So, you use the Builder pattern when:

  • the object to be constructed has many parts and might have different representations.
  • you need control over the construction process.