Builder Design Pattern Introduction04:33

  • 0
Published on October 7, 2017

In this video we will learn
1. What is Builder Design Pattern
2. Implementation Guidelines
3. Builder design pattern in action

What is Builder Design Pattern

Gang Of Four Definition

Builder Pattern belongs to creational pattern

Definition: “Separate the construction of a complex object from its representation so that the same construction process can create different representations”

Builder Pattern solves the situation of increasing constructor parameters and
Constructors of a given class by providing a step by step initialization of
Parameters. After step by step initialization, it returns the resulting constructed
Object at once

Implementation Guidelines

We need to Choose Builder Design Pattern when
1. We need to break up the construction of a complex object
2. We need to create a complex object and it should be independent of the parts that make up the object
3. The construction process must allow multiple representations of the same class

Business Requirement

Provide an option to choose and build configuration of the system which is allocated to the employees. The configuration options that user can choose are RAM, HDD, USB Mouse. Etc

If you look at the illustrated diagram of Builder Design Pattern

1. Builder: Defines a template for the steps to construct the product. To simplify, Builder Specifies an abstract interface for creating parts of a Product object.
2. Concrete Builder: Implements the builder interface and provides an interface for getting the product.
3. Director: Is responsible to constructs the object through the builder interface.
4. Product: is the Main object that’s constructed and Represents the complex object.

Steps to solve the above business requirement

Step 1: Add SystemConfigurationDetails to the existing Employee table

Step 2: Open EmployeePortal.edmx under the Models folder of the solution and update the model from the database (Right click on the model designer and choose update from database option)

Step 3: Create BuildSystem Action method and generate a view out of it.

Step 4: Create a new class and name it as computer system with RAM and HDDSize as the constructor parameters and Build as method that builds the system

Step 5: To the added BuildSystem view add dropdown lists to choose RAM and HDDSize.

Step 6: Create an action method BuildSystem to build the system on Submit.

Step 7: Run the application and Build a system for selected employee

Step 8: Choose the configurations and click on create to build the system

Though we have achieved the business requirement

The current approach will not fit if we need to add more configurations to the current system and it gets complicated.

Also, if we need to enhance the current code itself to segregate the configurations differently between a laptop and desktop the current approach is not feasible and it becomes complicated.

In these kind of situations builder pattern comes to our rescue to address these problems.

In the next session let’s discuss how we can address these problems using Builder design pattern.

Text version of the video

Slides

Design Patterns Tutorial playlist

Design Patterns Text articles and slides

All Dot Net and SQL Server Tutorials in English

All Dot Net and SQL Server Tutorials in Arabic

Enjoyed this video?
"No Thanks. Please Close This Box!"