Pattern Name:
Builder Pattern
Separate representation and object construction
Usage:
Rarely used, only useful if complex objects consisting of multiple parts need to be constructed (composite objects for example)
1 / 5
UML Class Diagram:
Explanation:
- The director (ComputerShop) implements a method that is responsible for the sequence of steps of an object creation process. It takes an abstract builder class as input parameter and delegates the real creation to it.
- The abstract builder class defines the interface that all inheriting concrete builders will use for object creation.
- The concrete builder implementations contain the parts that are assembled and that build the objects.
- The final object contains all different parts that get assembled by the concrete builder classes. Those may differ from each other depending on the implementations.
- A method was added that prints out the characteristics of the different parts to be able to validate the design.
- In the last step we add some code to test the software design and the Builder implementation.
- When running the example you can see that everything is working as expected and that the correct classes are instantiated during runtime.
Source Code:
http://csharpdesignpatterns.codeplex.com/
No comments:
Post a Comment