12
Builder A Creational Design Pattern A Presentation by Alex Bluhm And

Builder A Creational Design Pattern

  • Upload
    bayard

  • View
    35

  • Download
    0

Embed Size (px)

DESCRIPTION

Builder A Creational Design Pattern. A Presentation by Alex Bluhm And. What are Creational Design Patterns?. Creational Design Patterns. Abstract instantiation process Flexibility in what’s created, who creates it, how it’s created and when Patterns: Abstract Factory Builder - PowerPoint PPT Presentation

Citation preview

Page 1: Builder A Creational Design Pattern

BuilderA Creational Design Pattern

A Presentation by Alex Bluhm

And

Page 2: Builder A Creational Design Pattern

What are Creational Design Patterns?

Page 3: Builder A Creational Design Pattern

Creational Design Patterns

• Abstract instantiation process

• Flexibility in what’s created, who creates it, how it’s created and when

• Patterns:– Abstract Factory– Builder– Factory Method– Prototype– Singleton

Page 4: Builder A Creational Design Pattern

Builder Design Pattern• Separates the construction of a complex

object from its representation• Same construction process can create

different representations• Bob says… Builders specify abstract

interfaces for creating parts of a Product object

Page 5: Builder A Creational Design Pattern

Participants in Builder Pattern

• Builder• ConcreteBuilder• Director• Product

• Builder• ConcreteBuilder• Director• Product

Page 6: Builder A Creational Design Pattern

Product

ConcreteBuilder

buildPartA()buildPartB()getResult()

Director

construct()

Builder

buildPartA()buildPartB()

Client

for all parts in structure { builder->buildPart()}

Structure for Participants

Page 7: Builder A Creational Design Pattern

Builder Pattern Interaction

aClient aDirector aConcreteBuilder

new ConcreteBuilder

new Director(aConcreteBuilder)

construct() buildPartA()

buildPartB()

buildPartC()

getResult()

Page 8: Builder A Creational Design Pattern

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 they’re assembled

• When the construction process must allow different representations for the object that’s constructed

• When building a composite structural object

Page 9: Builder A Creational Design Pattern

Key Consequence of Builder Pattern

• Vary a product’s internal representation• Isolates code for construction and representation

Don’t forget that the Builder Design Pattern also gives you

finer control over the construction process!

Page 10: Builder A Creational Design Pattern

How to code a builder

• Assembly and Construction Interface

• No abstract class for products

• Empty methods as default in BuilderClass MazeBuilder {Public: virtual void BuildMaze() { } virtual void BuildRoom(int room) { } virtual void BuildDoor(int roomFrom, int roomTo) { }

virtual Maze* GetMaze() { return 0;}Protected: MazeBuilder();};

Page 11: Builder A Creational Design Pattern

Other Creational Patterns

• Object Creation– Abstract Factory– Prototype– Singleton

• Class Creation– Factory Method

Page 12: Builder A Creational Design Pattern

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

• Bob the Builder