Builder design patterns
-
Upload
pawan-naik -
Category
Documents
-
view
220 -
download
0
Transcript of Builder design patterns
-
7/30/2019 Builder design patterns
1/14
Builder DesignPatterns
By:
PAWAN R NAIK
1MS09IS066
ISE 8 B
-
7/30/2019 Builder design patterns
2/14
One of the Creational Pattern
Intent:
Separates the construction of a complex object from
its representation so that the same construction
process can create different representations.
-
7/30/2019 Builder design patterns
3/14
Creational Design Patterns
Abstract instantiation process
Flexibility in whats created, who creates it, how its
created and when it is created.
Patterns:
Abstract Factory
Builder
Factory Method
Prototype
Singleton
-
7/30/2019 Builder design patterns
4/14
Builder Design Pattern
Separates the construction of a complex object
from its representation.
Same construction process can create different
representations.
-
7/30/2019 Builder design patterns
5/14
Participants in Builder Pattern
Builder
ConcreteBuilder
Director
Product
-
7/30/2019 Builder design patterns
6/14
Product
ConcreteBuilder
buildPartA()
buildPartB()
getResult()
Director
construct()
Builder
buildPartA()buildPartB()
Client
for all parts in structure
{
builder->buildPart()
}
Structure for Participants
-
7/30/2019 Builder design patterns
7/14
Builder Pattern Interaction
Client Director ConcreteBuilder
new ConcreteBuilder
new Director(aConcreteBuilder)
construct() buildPartA()
buildPartB()
buildPartC()
getResult()
-
7/30/2019 Builder design patterns
8/14
Builder pattern interaction example
-
7/30/2019 Builder design patterns
9/14
When to use a Builder Pattern
When the algorithm for building a complex object should be
independent of the parts that make up the object and how
theyre assembled.
When the construction process must allow differentrepresentations for the object thats constructed.
When building a composite structural object.
-
7/30/2019 Builder design patterns
10/14
Key Consequence of Builder
Pattern Vary a products internal representation.
Isolates code for construction and representation.
greater control over construction process
-
7/30/2019 Builder design patterns
11/14
DisadvantageRequires creating a separate ConcreteBuilder for each
different type of Product.
-
7/30/2019 Builder design patterns
12/14
How to code a builder
Assembly and Construction Interface.
No abstract class for products.
Empty methods as default in Builder.
Class MazeBuilder {
Public:
virtual void BuildMaze() { }
virtual void BuildRoom(int room) { }
virtual void BuildDoor(int roomFrom, int roomTo) { }
virtual Maze* GetMaze() { return 0;}
Protected:
MazeBuilder();
};
-
7/30/2019 Builder design patterns
13/14
Special Thanks Design Patterns. Elements of Reusable Object-Oriented Software.
Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides.
Provider of Design Pattern PowerPoint slides online.(http://vik.ktu.lt/moduliai/).
-
7/30/2019 Builder design patterns
14/14
THANK YOU!