SlideShare a Scribd company logo
1 of 16
Download to read offline
Builder Design Pattern
Generic Construction - Different Representation
Sameer Singh Rathoud
About presentation
This presentation provide information to understand builder design pattern, it’s
structure, it’s implementation.
I have tried my best to explain the concept in very simple language.

The programming language used for implementation is c#. But any one from
different programming background can easily understand the implementation.
Definition
Separate the construction of complex object from its representation, such that

same construction process can be used to build different representation.

Builder pattern is a creational design pattern.
Motivation and Intent
At times, application contains complex objects and these complex objects are
made of other objects. Such application requires a generic mechanism to build

these complex object and related objects.

• Separate the construction of complex object from its representation.
• Same construction process is used to create different representation.
Structure
Director
Construct()

Builder.Buildpart()

builder

<< interface >>
Builder

<< interface >>
Product

BuildPart()
Inheritance
Concrete BuilderA

Concrete BuilderB

BuildPart()

BuildPart()
GetProduct()

GetProduct()

Inheritance
Concrete ProductA

Concrete ProductB
Participants in structure
• Director: Construct a object using Builder interface. Client interacts with the Director.
• Builder (interface): Provides an abstract interface for creating parts of the Product object.
• Product (interface): Provides an interface for Product family.
Participants in structure continue …
• ConcreteBuilder (Concrete BuilderA and Concrete BuilderB): Provides implementation to
Builder interface
• Construct and assembles parts of the Product object.

• Define and keeps track of representation it creates.
• Provide an interface for retrieving the Product object (GetProduct()).
• ConcreteProduct (Concrete ProductA and Concrete ProductB): Implements Product interface.

• Represents the complex object under construction. ConcreteBuilder builds the product's
internal representation and defines the process by which it's assembled.
• Includes classes that define the constituent parts, including interfaces for assembling the
parts into the final result.
Collaborations
• The client creates the Director object and configures it with the desired Builder object.
• Director notifies the builder whenever a part of the product should be built.

• Builder handles requests from the director and adds parts to the product.
• The client retrieves the product from the builder/Director.
Client

new Concrete Builder

Director

Concrete Builder

new Director(Concrete Builder)
Construct()

BuildPart1()
BuildPart2()
BuildPart3()

GetResult()
Implementation (C#)
Product (Interface)
public abstract class Vehicle {
private string mEngine;
public string Engine {
get { return mEngine; }
set { mEngine = value; }
}

private string mInterior;
public string Interior {
get { return mInterior; }
set { mInterior = value; }
}
public abstract void Drive();

private string mBrakingSystem;
}
public string BrakingSystem {
get { return mBrakingSystem; }
set { mBrakingSystem = value; }
}

private string mBody;
public string Body {
get { return mBody; }
set { mBody = value; }
}

Here “Vehicle” is an
abstract class with some
“properties” and abstract
method “Drive”. Now all
the
concrete
classes
implementing this abstract
class will inherit these
properties and will override
“Drive” method.

<< interface >> Product
- mEngine (string)
+ Engine { get set }

- mBody (string)
+ Body { get set }

- mBrakingSystem (string)
+ BrakingSystem { get set }
+ Drive ()

- mInterior (string)
+ Interior { get set }
Implementation (C#)
ConcreteProduct
class Car : Vehicle {
public override void Drive() {
System.Console.WriteLine("Drive Car");
}
}
class Truck : Vehicle {
public override void Drive() {
System.Console.WriteLine("Drive Truck");
}
}

Here the concrete classes “Car” and “Truck” are
implementing abstract class “Vehicle” and these
concrete classes are inheriting the properties and
overriding method “Drive” (giving class specific
definition of function) of “Vehicle” class.
<< interface >> Product

- mEngine (string)
+ Engine { get set }

- mBody (string)
+ Body { get set }

- mBrakingSystem (string)
+ BrakingSystem { get set }

- mInterior (string)
+ Interior { get set }

+ Drive ()

Car

Truck

Drive ()

Drive ()
Implementation (C#)
Builder (interface)
public abstract class VehicleBuilder {
protected Vehicle vehicle;

public abstract void
public abstract void
public abstract void
public abstract void

BuildEngine();
BuildBrakingSystem();
BuildBody();
BuildInterior();

public Vehicle GetVehicle() {
return vehicle;
}
}

Here “VehicleBuilder” is an abstract
builder class having the reference of
“Vehicle” object, few abstract methods
for setting the properties of “Vehicle”
and method for returning the fully
constructed “Vehicle” object. Here this
“VehicleBuilder”
class
is
also
responsible for assembling the entire
“Vehicle” object.
<< interface >> VehicleBuilder

- vehicle (Vehicle)
+ BuildEngine ()

+ BuildBody ()

+ BuildBrakingSystem ()

+ BuildInterior ()

+ GetVehicle ()
Implementation (C#)
ConcreteBuilder
class CarBuilder : VehicleBuilder {
public CarBuilder() {
vehicle = new Car();
}
public override void BuildEngine() {
vehicle.Engine = "Car Engine";
}
public override void BuildBrakingSystem() {
vehicle.BrakingSystem = "Car Braking System";
}
public override void BuildBody() {
vehicle.Body = "Car Body";
}
public override void BuildInterior() {
vehicle.Interior = "Car Interior";
}
}

Here “CarBuilder” is a concrete class
implementing “VehicleBuilder” class. In the
constructor of “CarBuilder”, “Car” object is
assigned to the reference of “Vehicle” and
class “CarBuilder” overrides the abstract
methods defined in “Vehicle” class.
<< interface >> VehicleBuilder
- vehicle (Vehicle)
+ BuildEngine ()

+ BuildBody ()

+ BuildBrakingSystem () + BuildInterior ()
+ GetVehicle ()

CarBuilder

+ BuildEngine ()
+ BuildBrakingSystem ()

+ BuildBody ()
+ BuildInterior ()
Implementation (C#)
ConcreteBuilder
class TruckBuilder : VehicleBuilder {
public TruckBuilder() {
vehicle = new Truck();
}
public override void BuildEngine() {
vehicle.Engine = "Truck Engine";
}
public override void BuildBrakingSystem() {
vehicle.BrakingSystem = "Truck Braking System";
}
public override void BuildBody() {
vehicle.Body = "Truck Body";
}
public override void BuildInterior() {
vehicle.Interior = "Truck Interior";
}
}

Here “TruckBuilder” is another concrete
class implementing “VehicleBuilder” class.
In the constructor of “TruckBuilder”,
“Truck” object is assigned to the reference
of “Vehicle” and class “TruckBuilder”
overrides the abstract methods defined in
“Vehicle” class.
<< interface >> VehicleBuilder

- vehicle (Vehicle)
+ BuildEngine ()

+ BuildBody ()
+ BuildBrakingSystem () + BuildInterior ()
+ GetVehicle ()

TruckBuilder
+ BuildEngine ()
+ BuildBrakingSystem ()

+ BuildBody ()
+ BuildInterior ()
Implementation (C#)
Director
class VehicleMaker {
private VehicleBuilder vehicleBuilder;
public VehicleMaker(VehicleBuilder builder) {
vehicleBuilder = builder;
}
public void BuildVehicle() {
vehicleBuilder.BuildEngine();
vehicleBuilder.BuildBrakingSystem();
vehicleBuilder.BuildBody();
vehicleBuilder.BuildInterior();
}

Here “VehicleMaker” is a class acting as
“Director” for builder pattern. This class
will
have
a
reference
of
“VehicleBuilder”. In the constructor of
“VehicleMaker” appropriate builder will
get assigned to the reference of
“VehicleBuilder”. Additionally this class
implements
“BuildVehicle”
and
“GetVehicle”
methods.
“BuildVehicle” will create the different
parts of the vehicle and “GetVehicle” will
return the fully constructed “Vehicle”
object
by
calling
the
“VehicleBuilder.GetVehicle”
method.

public Vehicle GetVehicle() {
return vehicleBuilder.GetVehicle();
}

VehicleMaker

}
+ BuildVehicle ()

+ GetVehicle ()
Implementation (C#)
Client
class Client {
static void Main(string[] args) {
VehicleBuilder carBuilder = new CarBuilder();
VehicleMaker maker1 = new VehicleMaker(carBuilder);
maker1.BuildVehicle();
Vehicle car = carBuilder.GetVehicle();
car.Drive();
VehicleBuilder truckBuilder = new TruckBuilder();
VehicleMaker maker2 = new VehicleMaker(truckBuilder);
maker2.BuildVehicle();
Vehicle truck = truckBuilder.GetVehicle();
truck.Drive();

}
}

For using this builder pattern the
client has to create a required
“VehicleBuilder” object and a
“VehicleMaker” object, pass the
created
object
of
“VehicleBuilder”
to
the
constructor of “VehicleMaker”.
Call the “BuildVehicle” from
“VehicleMaker” object (this call
will create the “Vehicle” and
assemble it) and we will get the
constructed “Vehicle” by calling
the
“GetVehicle”
from
“VehicleBuilder” object.
End of Presentation . . .

More Related Content

What's hot

What's hot (20)

Junit
JunitJunit
Junit
 
Visitor pattern
Visitor patternVisitor pattern
Visitor pattern
 
Design Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternDesign Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory Pattern
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 
NestJS
NestJSNestJS
NestJS
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Java Multithreading Using Executors Framework
Java Multithreading Using Executors FrameworkJava Multithreading Using Executors Framework
Java Multithreading Using Executors Framework
 
Correction Examen 2016-2017 POO .pdf
Correction Examen 2016-2017 POO .pdfCorrection Examen 2016-2017 POO .pdf
Correction Examen 2016-2017 POO .pdf
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
Qualité de code et bonnes pratiques
Qualité de code et bonnes pratiquesQualité de code et bonnes pratiques
Qualité de code et bonnes pratiques
 
Decorator Pattern
Decorator PatternDecorator Pattern
Decorator Pattern
 
Jetpack Compose beginner.pdf
Jetpack Compose beginner.pdfJetpack Compose beginner.pdf
Jetpack Compose beginner.pdf
 
Facade Design Pattern
Facade Design PatternFacade Design Pattern
Facade Design Pattern
 
Cours java
Cours javaCours java
Cours java
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
Software Engineering - chp4- design patterns
Software Engineering - chp4- design patternsSoftware Engineering - chp4- design patterns
Software Engineering - chp4- design patterns
 
Visitor design pattern
Visitor design patternVisitor design pattern
Visitor design pattern
 

Viewers also liked

Design pattern builder 20131115
Design pattern   builder 20131115Design pattern   builder 20131115
Design pattern builder 20131115LearningTech
 
Builder pattern
Builder pattern Builder pattern
Builder pattern mentallog
 
Design Patterns: Builder pattern (Le monteur)
Design Patterns: Builder pattern (Le monteur)Design Patterns: Builder pattern (Le monteur)
Design Patterns: Builder pattern (Le monteur)RadhoueneRouached
 
Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder paramisoft
 
Strategy Pattern
Strategy PatternStrategy Pattern
Strategy PatternGuo Albert
 
Python: Common Design Patterns
Python: Common Design PatternsPython: Common Design Patterns
Python: Common Design PatternsDamian T. Gordon
 
Strategy Design Pattern
Strategy Design PatternStrategy Design Pattern
Strategy Design PatternGanesh Kolhe
 

Viewers also liked (11)

Design pattern builder 20131115
Design pattern   builder 20131115Design pattern   builder 20131115
Design pattern builder 20131115
 
Builder pattern
Builder pattern Builder pattern
Builder pattern
 
Design Patterns: Builder pattern (Le monteur)
Design Patterns: Builder pattern (Le monteur)Design Patterns: Builder pattern (Le monteur)
Design Patterns: Builder pattern (Le monteur)
 
Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder
 
Strategy Pattern
Strategy PatternStrategy Pattern
Strategy Pattern
 
Strategy Pattern
Strategy PatternStrategy Pattern
Strategy Pattern
 
Python: Design Patterns
Python: Design PatternsPython: Design Patterns
Python: Design Patterns
 
Python: Common Design Patterns
Python: Common Design PatternsPython: Common Design Patterns
Python: Common Design Patterns
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
 
Strategy Design Pattern
Strategy Design PatternStrategy Design Pattern
Strategy Design Pattern
 
Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)
 

Similar to Builder Design Pattern (Generic Construction -Different Representation)

How to create an Angular builder
How to create an Angular builderHow to create an Angular builder
How to create an Angular builderMaurizio Vitale
 
Decorator design pattern (A Gift Wrapper)
Decorator design pattern (A Gift Wrapper)Decorator design pattern (A Gift Wrapper)
Decorator design pattern (A Gift Wrapper)Sameer Rathoud
 
Use Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDEUse Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDEBenjamin Cabé
 
Jan 2017 - a web of applications (angular 2)
Jan 2017 - a web of applications (angular 2)Jan 2017 - a web of applications (angular 2)
Jan 2017 - a web of applications (angular 2)Kasper Reijnders
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1Shahzad
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design PatternKanushka Gayan
 
Dark side of Android apps modularization
Dark side of Android apps modularizationDark side of Android apps modularization
Dark side of Android apps modularizationDavid Bilík
 
Factory method pattern (Virtual Constructor)
Factory method pattern (Virtual Constructor)Factory method pattern (Virtual Constructor)
Factory method pattern (Virtual Constructor)Sameer Rathoud
 
Design pattern builder 20131115
Design pattern   builder 20131115Design pattern   builder 20131115
Design pattern builder 20131115LearningTech
 
Building a TV show with Angular, Bootstrap, and Web Services
Building a TV show with Angular, Bootstrap, and Web ServicesBuilding a TV show with Angular, Bootstrap, and Web Services
Building a TV show with Angular, Bootstrap, and Web ServicesDavid Giard
 
Protocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftProtocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftOleksandr Stepanov
 
AppDevKit for iOS Development
AppDevKit for iOS DevelopmentAppDevKit for iOS Development
AppDevKit for iOS Developmentanistar sung
 
Padroes Projeto
Padroes ProjetoPadroes Projeto
Padroes Projetolcbj
 

Similar to Builder Design Pattern (Generic Construction -Different Representation) (20)

Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
How to create an Angular builder
How to create an Angular builderHow to create an Angular builder
How to create an Angular builder
 
Decorator design pattern (A Gift Wrapper)
Decorator design pattern (A Gift Wrapper)Decorator design pattern (A Gift Wrapper)
Decorator design pattern (A Gift Wrapper)
 
Use Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDEUse Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDE
 
Jan 2017 - a web of applications (angular 2)
Jan 2017 - a web of applications (angular 2)Jan 2017 - a web of applications (angular 2)
Jan 2017 - a web of applications (angular 2)
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Dark side of Android apps modularization
Dark side of Android apps modularizationDark side of Android apps modularization
Dark side of Android apps modularization
 
Factory method pattern (Virtual Constructor)
Factory method pattern (Virtual Constructor)Factory method pattern (Virtual Constructor)
Factory method pattern (Virtual Constructor)
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Design pattern builder 20131115
Design pattern   builder 20131115Design pattern   builder 20131115
Design pattern builder 20131115
 
Building a TV show with Angular, Bootstrap, and Web Services
Building a TV show with Angular, Bootstrap, and Web ServicesBuilding a TV show with Angular, Bootstrap, and Web Services
Building a TV show with Angular, Bootstrap, and Web Services
 
Foundations of programming
Foundations of programmingFoundations of programming
Foundations of programming
 
Protocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftProtocol-Oriented Programming in Swift
Protocol-Oriented Programming in Swift
 
AppDevKit for iOS Development
AppDevKit for iOS DevelopmentAppDevKit for iOS Development
AppDevKit for iOS Development
 
Padroes Projeto
Padroes ProjetoPadroes Projeto
Padroes Projeto
 
Clean Architecture @ Taxibeat
Clean Architecture @ TaxibeatClean Architecture @ Taxibeat
Clean Architecture @ Taxibeat
 
Modern android development
Modern android developmentModern android development
Modern android development
 

More from Sameer Rathoud

Observer design pattern
Observer design patternObserver design pattern
Observer design patternSameer Rathoud
 
Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())Sameer Rathoud
 
Proxy design pattern (Class Ambassador)
Proxy design pattern (Class Ambassador)Proxy design pattern (Class Ambassador)
Proxy design pattern (Class Ambassador)Sameer Rathoud
 
Singleton Pattern (Sole Object with Global Access)
Singleton Pattern (Sole Object with Global Access)Singleton Pattern (Sole Object with Global Access)
Singleton Pattern (Sole Object with Global Access)Sameer Rathoud
 

More from Sameer Rathoud (6)

Platformonomics
PlatformonomicsPlatformonomics
Platformonomics
 
AreWePreparedForIoT
AreWePreparedForIoTAreWePreparedForIoT
AreWePreparedForIoT
 
Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
 
Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())
 
Proxy design pattern (Class Ambassador)
Proxy design pattern (Class Ambassador)Proxy design pattern (Class Ambassador)
Proxy design pattern (Class Ambassador)
 
Singleton Pattern (Sole Object with Global Access)
Singleton Pattern (Sole Object with Global Access)Singleton Pattern (Sole Object with Global Access)
Singleton Pattern (Sole Object with Global Access)
 

Recently uploaded

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 

Recently uploaded (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 

Builder Design Pattern (Generic Construction -Different Representation)

  • 1. Builder Design Pattern Generic Construction - Different Representation Sameer Singh Rathoud
  • 2. About presentation This presentation provide information to understand builder design pattern, it’s structure, it’s implementation. I have tried my best to explain the concept in very simple language. The programming language used for implementation is c#. But any one from different programming background can easily understand the implementation.
  • 3. Definition Separate the construction of complex object from its representation, such that same construction process can be used to build different representation. Builder pattern is a creational design pattern.
  • 4. Motivation and Intent At times, application contains complex objects and these complex objects are made of other objects. Such application requires a generic mechanism to build these complex object and related objects. • Separate the construction of complex object from its representation. • Same construction process is used to create different representation.
  • 5. Structure Director Construct() Builder.Buildpart() builder << interface >> Builder << interface >> Product BuildPart() Inheritance Concrete BuilderA Concrete BuilderB BuildPart() BuildPart() GetProduct() GetProduct() Inheritance Concrete ProductA Concrete ProductB
  • 6. Participants in structure • Director: Construct a object using Builder interface. Client interacts with the Director. • Builder (interface): Provides an abstract interface for creating parts of the Product object. • Product (interface): Provides an interface for Product family.
  • 7. Participants in structure continue … • ConcreteBuilder (Concrete BuilderA and Concrete BuilderB): Provides implementation to Builder interface • Construct and assembles parts of the Product object. • Define and keeps track of representation it creates. • Provide an interface for retrieving the Product object (GetProduct()). • ConcreteProduct (Concrete ProductA and Concrete ProductB): Implements Product interface. • Represents the complex object under construction. ConcreteBuilder builds the product's internal representation and defines the process by which it's assembled. • Includes classes that define the constituent parts, including interfaces for assembling the parts into the final result.
  • 8. Collaborations • The client creates the Director object and configures it with the desired Builder object. • Director notifies the builder whenever a part of the product should be built. • Builder handles requests from the director and adds parts to the product. • The client retrieves the product from the builder/Director. Client new Concrete Builder Director Concrete Builder new Director(Concrete Builder) Construct() BuildPart1() BuildPart2() BuildPart3() GetResult()
  • 9. Implementation (C#) Product (Interface) public abstract class Vehicle { private string mEngine; public string Engine { get { return mEngine; } set { mEngine = value; } } private string mInterior; public string Interior { get { return mInterior; } set { mInterior = value; } } public abstract void Drive(); private string mBrakingSystem; } public string BrakingSystem { get { return mBrakingSystem; } set { mBrakingSystem = value; } } private string mBody; public string Body { get { return mBody; } set { mBody = value; } } Here “Vehicle” is an abstract class with some “properties” and abstract method “Drive”. Now all the concrete classes implementing this abstract class will inherit these properties and will override “Drive” method. << interface >> Product - mEngine (string) + Engine { get set } - mBody (string) + Body { get set } - mBrakingSystem (string) + BrakingSystem { get set } + Drive () - mInterior (string) + Interior { get set }
  • 10. Implementation (C#) ConcreteProduct class Car : Vehicle { public override void Drive() { System.Console.WriteLine("Drive Car"); } } class Truck : Vehicle { public override void Drive() { System.Console.WriteLine("Drive Truck"); } } Here the concrete classes “Car” and “Truck” are implementing abstract class “Vehicle” and these concrete classes are inheriting the properties and overriding method “Drive” (giving class specific definition of function) of “Vehicle” class. << interface >> Product - mEngine (string) + Engine { get set } - mBody (string) + Body { get set } - mBrakingSystem (string) + BrakingSystem { get set } - mInterior (string) + Interior { get set } + Drive () Car Truck Drive () Drive ()
  • 11. Implementation (C#) Builder (interface) public abstract class VehicleBuilder { protected Vehicle vehicle; public abstract void public abstract void public abstract void public abstract void BuildEngine(); BuildBrakingSystem(); BuildBody(); BuildInterior(); public Vehicle GetVehicle() { return vehicle; } } Here “VehicleBuilder” is an abstract builder class having the reference of “Vehicle” object, few abstract methods for setting the properties of “Vehicle” and method for returning the fully constructed “Vehicle” object. Here this “VehicleBuilder” class is also responsible for assembling the entire “Vehicle” object. << interface >> VehicleBuilder - vehicle (Vehicle) + BuildEngine () + BuildBody () + BuildBrakingSystem () + BuildInterior () + GetVehicle ()
  • 12. Implementation (C#) ConcreteBuilder class CarBuilder : VehicleBuilder { public CarBuilder() { vehicle = new Car(); } public override void BuildEngine() { vehicle.Engine = "Car Engine"; } public override void BuildBrakingSystem() { vehicle.BrakingSystem = "Car Braking System"; } public override void BuildBody() { vehicle.Body = "Car Body"; } public override void BuildInterior() { vehicle.Interior = "Car Interior"; } } Here “CarBuilder” is a concrete class implementing “VehicleBuilder” class. In the constructor of “CarBuilder”, “Car” object is assigned to the reference of “Vehicle” and class “CarBuilder” overrides the abstract methods defined in “Vehicle” class. << interface >> VehicleBuilder - vehicle (Vehicle) + BuildEngine () + BuildBody () + BuildBrakingSystem () + BuildInterior () + GetVehicle () CarBuilder + BuildEngine () + BuildBrakingSystem () + BuildBody () + BuildInterior ()
  • 13. Implementation (C#) ConcreteBuilder class TruckBuilder : VehicleBuilder { public TruckBuilder() { vehicle = new Truck(); } public override void BuildEngine() { vehicle.Engine = "Truck Engine"; } public override void BuildBrakingSystem() { vehicle.BrakingSystem = "Truck Braking System"; } public override void BuildBody() { vehicle.Body = "Truck Body"; } public override void BuildInterior() { vehicle.Interior = "Truck Interior"; } } Here “TruckBuilder” is another concrete class implementing “VehicleBuilder” class. In the constructor of “TruckBuilder”, “Truck” object is assigned to the reference of “Vehicle” and class “TruckBuilder” overrides the abstract methods defined in “Vehicle” class. << interface >> VehicleBuilder - vehicle (Vehicle) + BuildEngine () + BuildBody () + BuildBrakingSystem () + BuildInterior () + GetVehicle () TruckBuilder + BuildEngine () + BuildBrakingSystem () + BuildBody () + BuildInterior ()
  • 14. Implementation (C#) Director class VehicleMaker { private VehicleBuilder vehicleBuilder; public VehicleMaker(VehicleBuilder builder) { vehicleBuilder = builder; } public void BuildVehicle() { vehicleBuilder.BuildEngine(); vehicleBuilder.BuildBrakingSystem(); vehicleBuilder.BuildBody(); vehicleBuilder.BuildInterior(); } Here “VehicleMaker” is a class acting as “Director” for builder pattern. This class will have a reference of “VehicleBuilder”. In the constructor of “VehicleMaker” appropriate builder will get assigned to the reference of “VehicleBuilder”. Additionally this class implements “BuildVehicle” and “GetVehicle” methods. “BuildVehicle” will create the different parts of the vehicle and “GetVehicle” will return the fully constructed “Vehicle” object by calling the “VehicleBuilder.GetVehicle” method. public Vehicle GetVehicle() { return vehicleBuilder.GetVehicle(); } VehicleMaker } + BuildVehicle () + GetVehicle ()
  • 15. Implementation (C#) Client class Client { static void Main(string[] args) { VehicleBuilder carBuilder = new CarBuilder(); VehicleMaker maker1 = new VehicleMaker(carBuilder); maker1.BuildVehicle(); Vehicle car = carBuilder.GetVehicle(); car.Drive(); VehicleBuilder truckBuilder = new TruckBuilder(); VehicleMaker maker2 = new VehicleMaker(truckBuilder); maker2.BuildVehicle(); Vehicle truck = truckBuilder.GetVehicle(); truck.Drive(); } } For using this builder pattern the client has to create a required “VehicleBuilder” object and a “VehicleMaker” object, pass the created object of “VehicleBuilder” to the constructor of “VehicleMaker”. Call the “BuildVehicle” from “VehicleMaker” object (this call will create the “Vehicle” and assemble it) and we will get the constructed “Vehicle” by calling the “GetVehicle” from “VehicleBuilder” object.