SlideShare a Scribd company logo
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 . . .
Ad

More Related Content

What's hot (20)

Typescript ppt
Typescript pptTypescript ppt
Typescript ppt
akhilsreyas
 
React-JS Component Life-cycle Methods
React-JS Component Life-cycle MethodsReact-JS Component Life-cycle Methods
React-JS Component Life-cycle Methods
ANKUSH CHAVAN
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
Shakil Ahmed
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Malla Reddy University
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern Presentation
JAINIK PATEL
 
Composite pattern
Composite patternComposite pattern
Composite pattern
Shakil Ahmed
 
Flyweight pattern
Flyweight patternFlyweight pattern
Flyweight pattern
Shakil Ahmed
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patterns
Amit Kabra
 
Introduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonIntroduction to Design Patterns and Singleton
Introduction to Design Patterns and Singleton
Jonathan Simon
 
Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1
Mindfire Solutions
 
Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method Pattern
Mudasir Qazi
 
TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
NexThoughts Technologies
 
Creational pattern
Creational patternCreational pattern
Creational pattern
Himanshu
 
Abstract class
Abstract classAbstract class
Abstract class
Tony Nguyen
 
Composite design pattern
Composite design patternComposite design pattern
Composite design pattern
MUHAMMAD FARHAN ASLAM
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
Jyaasa Technologies
 
Facade Design Pattern
Facade Design PatternFacade Design Pattern
Facade Design Pattern
Livares Technologies Pvt Ltd
 
Facade pattern
Facade patternFacade pattern
Facade pattern
Shakil Ahmed
 
Prototype_pattern
Prototype_patternPrototype_pattern
Prototype_pattern
Iryney Baran
 
Visitor design pattern
Visitor design patternVisitor design pattern
Visitor design pattern
Salem-Kabbani
 
React-JS Component Life-cycle Methods
React-JS Component Life-cycle MethodsReact-JS Component Life-cycle Methods
React-JS Component Life-cycle Methods
ANKUSH CHAVAN
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Malla Reddy University
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern Presentation
JAINIK PATEL
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patterns
Amit Kabra
 
Introduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonIntroduction to Design Patterns and Singleton
Introduction to Design Patterns and Singleton
Jonathan Simon
 
Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1
Mindfire Solutions
 
Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method Pattern
Mudasir Qazi
 
Creational pattern
Creational patternCreational pattern
Creational pattern
Himanshu
 
Visitor design pattern
Visitor design patternVisitor design pattern
Visitor design pattern
Salem-Kabbani
 

Viewers also liked (11)

Design pattern builder 20131115
Design pattern   builder 20131115Design pattern   builder 20131115
Design pattern builder 20131115
LearningTech
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
Jyaasa Technologies
 
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 Pattern
Shahriar Iqbal Chowdhury
 
Strategy Pattern
Strategy PatternStrategy Pattern
Strategy Pattern
Guo Albert
 
Python: Design Patterns
Python: Design PatternsPython: Design Patterns
Python: Design Patterns
Damian T. Gordon
 
Python: Common Design Patterns
Python: Common Design PatternsPython: Common Design Patterns
Python: Common Design Patterns
Damian T. Gordon
 
Strategy Design Pattern
Strategy Design PatternStrategy Design Pattern
Strategy Design Pattern
Ganesh Kolhe
 
Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)
Aniruddha Chakrabarti
 
Design pattern builder 20131115
Design pattern   builder 20131115Design pattern   builder 20131115
Design pattern builder 20131115
LearningTech
 
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 Pattern
Guo Albert
 
Python: Common Design Patterns
Python: Common Design PatternsPython: Common Design Patterns
Python: Common Design Patterns
Damian T. Gordon
 
Strategy Design Pattern
Strategy Design PatternStrategy Design Pattern
Strategy Design Pattern
Ganesh Kolhe
 
Ad

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

Design Patterns
Design PatternsDesign Patterns
Design Patterns
Sergio Ronchi
 
How to create an Angular builder
How to create an Angular builderHow to create an Angular builder
How to create an Angular builder
Maurizio Vitale
 
object oriented programming with C++ Constructors_Destructors.pptx
object oriented programming with C++ Constructors_Destructors.pptxobject oriented programming with C++ Constructors_Destructors.pptx
object oriented programming with C++ Constructors_Destructors.pptx
WasiqAslam1
 
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 IDE
Benjamin 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 Patterns
Design PatternsDesign Patterns
Design Patterns
Betclic Everest Group Tech Team
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
Kanushka Gayan
 
Design patterns
Design patternsDesign patterns
Design patterns
◄ vaquar khan ► ★✔
 
Dark side of Android apps modularization
Dark side of Android apps modularizationDark side of Android apps modularization
Dark side of Android apps modularization
David Bilík
 
Factory method pattern (Virtual Constructor)
Factory method pattern (Virtual Constructor)Factory method pattern (Virtual Constructor)
Factory method pattern (Virtual Constructor)
Sameer Rathoud
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
Pankhuree Srivastava
 
Design pattern builder 20131115
Design pattern   builder 20131115Design pattern   builder 20131115
Design pattern builder 20131115
LearningTech
 
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
David Giard
 
Foundations of programming
Foundations of programmingFoundations of programming
Foundations of programming
Stefan von Niederhäusern
 
Week 3 - OOP Constructor (1)classtas.pptx
Week 3 - OOP Constructor (1)classtas.pptxWeek 3 - OOP Constructor (1)classtas.pptx
Week 3 - OOP Constructor (1)classtas.pptx
NajamUlHassan73
 
Protocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftProtocol-Oriented Programming in Swift
Protocol-Oriented Programming in Swift
Oleksandr Stepanov
 
AppDevKit for iOS Development
AppDevKit for iOS DevelopmentAppDevKit for iOS Development
AppDevKit for iOS Development
anistar sung
 
Padroes Projeto
Padroes ProjetoPadroes Projeto
Padroes Projeto
lcbj
 
Clean Architecture @ Taxibeat
Clean Architecture @ TaxibeatClean Architecture @ Taxibeat
Clean Architecture @ Taxibeat
Michael Bakogiannis
 
How to create an Angular builder
How to create an Angular builderHow to create an Angular builder
How to create an Angular builder
Maurizio Vitale
 
object oriented programming with C++ Constructors_Destructors.pptx
object oriented programming with C++ Constructors_Destructors.pptxobject oriented programming with C++ Constructors_Destructors.pptx
object oriented programming with C++ Constructors_Destructors.pptx
WasiqAslam1
 
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 IDE
Benjamin 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
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
Kanushka Gayan
 
Dark side of Android apps modularization
Dark side of Android apps modularizationDark side of Android apps modularization
Dark side of Android apps modularization
David 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 20131115
LearningTech
 
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
David Giard
 
Week 3 - OOP Constructor (1)classtas.pptx
Week 3 - OOP Constructor (1)classtas.pptxWeek 3 - OOP Constructor (1)classtas.pptx
Week 3 - OOP Constructor (1)classtas.pptx
NajamUlHassan73
 
Protocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftProtocol-Oriented Programming in Swift
Protocol-Oriented Programming in Swift
Oleksandr Stepanov
 
AppDevKit for iOS Development
AppDevKit for iOS DevelopmentAppDevKit for iOS Development
AppDevKit for iOS Development
anistar sung
 
Padroes Projeto
Padroes ProjetoPadroes Projeto
Padroes Projeto
lcbj
 
Ad

More from Sameer Rathoud (6)

Platformonomics
PlatformonomicsPlatformonomics
Platformonomics
Sameer Rathoud
 
AreWePreparedForIoT
AreWePreparedForIoTAreWePreparedForIoT
AreWePreparedForIoT
Sameer Rathoud
 
Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
Sameer 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
 
Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
Sameer 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
 

Recently uploaded (20)

Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptxTop 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
mkubeusa
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
CSUC - Consorci de Serveis Universitaris de Catalunya
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Mike Mingos
 
AI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of DocumentsAI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of Documents
UiPathCommunity
 
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Agentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community MeetupAgentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community Meetup
Manoj Batra (1600 + Connections)
 
Build With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdfBuild With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdf
Google Developer Group - Harare
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptxTop 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
mkubeusa
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Mike Mingos
 
AI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of DocumentsAI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of Documents
UiPathCommunity
 
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 

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.
  翻译: