Presentation is loading. Please wait.

Presentation is loading. Please wait.

C# and Design Patterns Builder Pattern. 2 C# and Design Patterns Builder Pattern Object creational pattern Object creational pattern Separates construction.

Similar presentations


Presentation on theme: "C# and Design Patterns Builder Pattern. 2 C# and Design Patterns Builder Pattern Object creational pattern Object creational pattern Separates construction."— Presentation transcript:

1 C# and Design Patterns Builder Pattern

2 2 C# and Design Patterns Builder Pattern Object creational pattern Object creational pattern Separates construction of complex object from its representation Separates construction of complex object from its representation Construct an object step-by-step Construct an object step-by-step Usually builds composite objects Usually builds composite objects

3 3 C# and Design Patterns Goals and Context Create complex/composite objects in a step-by-step fashion Create complex/composite objects in a step-by-step fashion Client must build complex object without knowing its internal construction Client must build complex object without knowing its internal construction Separate creator from data providers Separate creator from data providers Different representations for complex object possible Different representations for complex object possible

4 4 C# and Design Patterns Architecture and Classes (1/2) Create a Builder class Create a Builder class Has methods for constructing the parts of the product Has methods for constructing the parts of the product Also, a method for retrieving the product Also, a method for retrieving the product The Builder builds the final product piece by piece The Builder builds the final product piece by piece

5 5 C# and Design Patterns Architecture and Classes (2/2) The Builder must be told how to proceed in the construction process The Builder must be told how to proceed in the construction process To this end, we create a Director class To this end, we create a Director class Director uses the Builder interface Director uses the Builder interface

6 6 C# and Design Patterns Class Diagram

7 7 C# and Design Patterns Sequence Diagram

8 8 C# and Design Patterns Advantages Separation of creator (Director) and data providers (Builder) Separation of creator (Director) and data providers (Builder) More fine-grained than Factory patterns More fine-grained than Factory patterns Step-by-step creating Step-by-step creating

9 9 C# and Design Patterns Application Areas Everywhere where you need to create complex objects in a step-by-step fashion Everywhere where you need to create complex objects in a step-by-step fashion

10 10 C# and Design Patterns Related Patterns Composite Composite The built objects are typically composites The built objects are typically composites Factories Factories Builder is a more fine-grained version of factory Builder is a more fine-grained version of factory Factory can be used to create builder objects Factory can be used to create builder objects

11 11 C# and Design Patterns Exercise


Download ppt "C# and Design Patterns Builder Pattern. 2 C# and Design Patterns Builder Pattern Object creational pattern Object creational pattern Separates construction."

Similar presentations


Ads by Google