Design Pattern: Builder - PowerPoint PPT Presentation

About This Presentation
Title:

Design Pattern: Builder

Description:

The Builder pattern is a way to: ... Want to hide the implementation of each construction step from other objects. ... Example: An auto manufacturing plant ... – PowerPoint PPT presentation

Number of Views:90
Avg rating:3.0/5.0
Slides: 16
Provided by: Tim8113
Category:

less

Transcript and Presenter's Notes

Title: Design Pattern: Builder


1
Design Pattern Builder
  • Timothy Holper

2
The Builder design pattern What is it?
  • The Builder pattern is a way to
  • Separate the construction of a complex object
    from its representation so that the same
    construction process can create different
    representations Grady Booch

3
The Builder design pattern When to use it?
  • You know you should be using the Builder design
    pattern when you
  • Want to create different complex objects, but use
    the same set of construction steps.
  • Allows you to vary the products internal
    representation.
  • Want to separate the steps used to create a
    complex object from the following
  • The parts involved in the creation of the
    product.
  • How the parts are actually assembled in the
    creation of the product.
  • Want to hide the implementation of each
    construction step from other objects.
  • There is only one object that DOES need to know
    how the product is assembled.

4
Why is the Builder design pattern significant?
  • Gives greater control over the object
    construction process
  • Product may only be created by going through one
    object.
  • That one object can keep track of how many
    products are created.
  • Product may only be created by following specific
    steps.
  • Allows you to easily vary the products internal
    representation without affecting other parts.
  • If you want to change how the product is actually
    built, while keeping the same set of steps, only
    one object needs to know about it.
  • This is good encapsulation.
  • The Code for construction and the code for
    representation are isolated.
  • Only interested parties need to know their part.
  • Once again, good encapsulation.
  • Overall, simplifies the project specification by
    only indicating the type and parts that the final
    product REQUIRES.
  • We can say, definitively, that given these parts
    and this set of steps, we will be able to produce
    a finished product.

5
Example An auto manufacturing plant
  • The plant builds only 2 types of cars, the AMC
    Gremlin and the AMC Pacer.
  • Both cars are built off of the same vehicle
    chassis (i.e. same frame and axles)
  • There are 2 teams which are in charge of building
    these cars, a Gremlin team and a Pacer team.
  • Both teams are using the same set of steps, in
    order, to construct these cars
  • Add transmission
  • Add engine
  • Add seats
  • Add body panels

6
Participants in the Builder design pattern
  • Director
  • Builds the complex object using the Builder
    interface.
  • Responsible for the overall construction process.
  • Delegates the actual creation/assembly of the
    object to the Concrete Builder/s.
  • Returns complex object to client.
  • Builder
  • Specifies the interface for creating the parts of
    the complex object.
  • Concrete Builder
  • Implements the Builder interface it chooses the
    parts that go into the complex object and
    assembles these parts that make up the object.
  • Provides interface for returning the object that
    is created.
  • Product
  • This is the complex object, the deliverable.
  • It is created by the Concrete Builder,
    implementing the Builder interface.

7
Your Concrete Builders Building different
products using the same set of construction steps
  • Add 3spd. Automatic Transmission
  • Add 6 Cylinder Engine
  • Add vinyl seats
  • Add Pacer body panels
  • Add 4spd. Manual Transmission
  • Add 4 Cylinder Engine
  • Add denim seats
  • Add Gremlin body panels

8
Code Example Driver
9
Code Example Director and Builder
10
Code Example Concrete Builders
11
Code Example Vehicle (Product)
12
Code Example Output
13
(No Transcript)
14
Code Example Director and Builder
15
Code Example Concrete Builders
Write a Comment
User Comments (0)
About PowerShow.com