The Builder pattern - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

The Builder pattern

Description:

Separates the construction of a complex object from its representation so that ... Get one of the GUIs. Example (4) public class ChoiceDirector ... – PowerPoint PPT presentation

Number of Views:29
Avg rating:3.0/5.0
Slides: 12
Provided by: pin57
Category:
Tags: builder | guis | pattern

less

Transcript and Presenter's Notes

Title: The Builder pattern


1
The Builder pattern
  • Shuanghui Luo

2
Type intent
  • 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.

3
Applicability
  • The Builder pattern assembles a number of objects
    in various ways depending on the data.
  • Use the Builder pattern when
  • the algorithm for creating a complex object
    should be independent on the parts that make up
    the object and how they're assembled.
  • the construction process must allow different
    representations for the object that's
    constructed.

4
Structure (UML Model)
5
Participants
  • Builder specifies an abstract interface for
    creating parts of a Product object.
  • ConcreteBuilder
  • constructs and assembles parts of the product by
    implementing the Builder interface.
  • Defines and keeps track of the representation it
    creates.
  • Provides an interface for retrieving the product.
  • Director constructs an object using the Builder
    interface.
  • Product represents the complex object under
    construction.

6
Consequences
  • Abstracts the construction implementation details
    of a class type. It lets you vary the internal
    representation of the product that it builds.
  • Encapsulates the way in which objects are
    constructed improving the modularity of a system.
  • Finer control over the creation process, by
    letting a builder class have multiple methods
    that are called in a sequence to create an
    object.
  • Each specific Builder is independent of any
    others.

7
Example (1)
  • A fathers-sons chooser
  • We have a list of fathers in a Jlist
  • We want to create a visual chooser for sons of
    the selected father
  • A JPanel with a JList, if sonsgt3
  • A JPanel with JCheckBoxes, if sonslt3

8
Example (2)
9
Example (3)
  • public class MainJPanel extends JPanel implements
    javax.swing.event.ListSelectionListener
  • public void valueChanged(javax.swing.event.ListSe
    lectionEvent e)
  • this.getSonsPanel().add(this.getCDirector().getC
    hoiceUI(v))
  • this.getSonsPanel().validate()
  • this.getSonsPanel().repaint()

10
Example (4)
  • public class ChoiceDirector
  • public javax.swing.JPanel getChoiceUI(java.util.V
    ector choices)
  • ChoiceAbstractBuilder p
  • if (choices.size() lt 3)
  • p new CheckBoxChoiceConcreteBuilder(choices)
  • else
  • p new ListChoiceConcreteBuilder(choices)
  • return p.getGUI()

11
References
  • http//hillside.net/patterns
  • http//www.cs.wustl.edu/schmidt/patterns.html
  • http//www.ciol.com/content/technology/sw_desg_pat
    t/toc.asp
  • http//www.research.umbc.edu/tarr/cs491/fall00/cs
    491.html
  • http//www.fh-konstanz.de/studium/ze/cim/projekte/
    osefa/patterns/builder/intent.htm
  • http//www.cs.washington.edu/homes/bdudash/designp
    atterns/builder.html
Write a Comment
User Comments (0)
About PowerShow.com