SlideShare uma empresa Scribd logo
1 de 16
Baixar para ler 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 . . .

Mais conteúdo relacionado

Mais procurados

Software design patterns ppt
Software design patterns pptSoftware design patterns ppt
Software design patterns pptmkruthika
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVCIndicThreads
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design patternMindfire Solutions
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)paramisoft
 
Unit 2-Design Patterns.ppt
Unit 2-Design Patterns.pptUnit 2-Design Patterns.ppt
Unit 2-Design Patterns.pptMsRAMYACSE
 
Design Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternDesign Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternMudasir Qazi
 
Java Collections
Java CollectionsJava Collections
Java Collectionsparag
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns pptAman Jain
 
Design pattern - Facade Pattern
Design pattern - Facade PatternDesign pattern - Facade Pattern
Design pattern - Facade PatternMudasir Qazi
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1Shahzad
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern PresentationJAINIK PATEL
 

Mais procurados (20)

Software design patterns ppt
Software design patterns pptSoftware design patterns ppt
Software design patterns ppt
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
 
Facade Pattern
Facade PatternFacade Pattern
Facade Pattern
 
Hibernate in Action
Hibernate in ActionHibernate in Action
Hibernate in Action
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)
 
Unit 2-Design Patterns.ppt
Unit 2-Design Patterns.pptUnit 2-Design Patterns.ppt
Unit 2-Design Patterns.ppt
 
Design Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternDesign Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory Pattern
 
Spring Core
Spring CoreSpring Core
Spring Core
 
Java Collections
Java CollectionsJava Collections
Java Collections
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
 
Design pattern - Facade Pattern
Design pattern - Facade PatternDesign pattern - Facade Pattern
Design pattern - Facade Pattern
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern Presentation
 

Destaque

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
 

Destaque (10)

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
 
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)
 

Semelhante a Builder Design Pattern - Generic Construction for Different Representations

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
 
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
 
Creational pattern 2
Creational pattern 2Creational pattern 2
Creational pattern 2Naga Muruga
 

Semelhante a Builder Design Pattern - Generic Construction for Different Representations (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
 
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
 
Creational pattern 2
Creational pattern 2Creational pattern 2
Creational pattern 2
 

Mais de 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
 

Mais de 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)
 

Último

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
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
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 

Último (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
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
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

Builder Design Pattern - Generic Construction for Different Representations

  • 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.