SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Downloaden Sie, um offline zu lesen
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 . . .

Weitere ähnliche Inhalte

Was ist angesagt?

Design pattern - Facade Pattern
Design pattern - Facade PatternDesign pattern - Facade Pattern
Design pattern - Facade PatternMudasir Qazi
 
Architectural styles and patterns
Architectural styles and patternsArchitectural styles and patterns
Architectural styles and patternsHimanshu
 
Software Engineering - chp4- design patterns
Software Engineering - chp4- design patternsSoftware Engineering - chp4- design patterns
Software Engineering - chp4- design patternsLilia Sfaxi
 
Design Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternDesign Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternMudasir Qazi
 
Architecture business cycle
Architecture business cycleArchitecture business cycle
Architecture business cycleHimanshu
 
Gof design pattern
Gof design patternGof design pattern
Gof design patternnaveen kumar
 
Design Patterns
Design PatternsDesign Patterns
Design Patternssoms_1
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)paramisoft
 
Agile Methodology - Software Engineering
Agile Methodology - Software EngineeringAgile Methodology - Software Engineering
Agile Methodology - Software EngineeringPurvik Rana
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design PatternSanae BEKKAR
 

Was ist angesagt? (20)

Design pattern - Facade Pattern
Design pattern - Facade PatternDesign pattern - Facade Pattern
Design pattern - Facade Pattern
 
Ch 9-design-engineering
Ch 9-design-engineeringCh 9-design-engineering
Ch 9-design-engineering
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Architectural styles and patterns
Architectural styles and patternsArchitectural styles and patterns
Architectural styles and patterns
 
Software Engineering - chp4- design patterns
Software Engineering - chp4- design patternsSoftware Engineering - chp4- design patterns
Software Engineering - chp4- design patterns
 
Design Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternDesign Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory Pattern
 
Facade Design Pattern
Facade Design PatternFacade Design Pattern
Facade Design Pattern
 
Architecture business cycle
Architecture business cycleArchitecture business cycle
Architecture business cycle
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
 
Facade pattern
Facade patternFacade pattern
Facade pattern
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)
 
Agile Methodology - Software Engineering
Agile Methodology - Software EngineeringAgile Methodology - Software Engineering
Agile Methodology - Software Engineering
 
Types of UML diagrams
Types of UML diagramsTypes of UML diagrams
Types of UML diagrams
 
Struts
StrutsStruts
Struts
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 
Design pattern-presentation
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
 

Andere mochten auch

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
 

Andere mochten auch (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)
 

Ähnlich wie 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
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1Shahzad
 
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
 

Ähnlich wie 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
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
 
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
 

Mehr von 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
 

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

Kürzlich hochgeladen

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
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
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Kürzlich hochgeladen (20)

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
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
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 

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.