


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Memon; Class: PROG LANG TECH & PDGMS; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;
Typology: Study notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!



1
Builder Pattern Mar. 13, 2007
parameters to the creation method(s).subclasses depending on the data passed viaFactory Pattern returns one of several different
(unrelated) objects.are assembled from different combinations ofthat are simple descendents of a base object, butSuppose we aren’t interested in returning objects
3
method(s).the data passed via parameters to the creationnumber of objects in various ways depending onThe Builder Pattern assembles and returns a
for us.Lets design a class that will build a User Interface
performance.investments and plot their comparativecategory so we can select one or more of thelike to display a list of our holdings in eachhave stocks, bonds and mutual funds, and we’dthe performance of our investments. We mightRequirements: write a program to keep track of
5
investment we might own at any given time.We cannot predict in advance how many of each kind of
of funds (such as mutual funds).large number of funds (such as stocks) or a small numberWe’d like to have a display that is easy to use for either a
that we can select one or more funds to plot.In each case, we want some kind of a multiple-choice display so
and if there are 3 or fewer funds, we’ll use a set of check boxes.If there is a large number of funds, we’ll use a multi-choice list box
have the same methods for returning the results.depends on the number of items to be displayed, and yetWe want our Builder class to generate an interface that
7
the methods we need to implementstart with a multiChoice abstract class that defines
multiple-choice display.The getUI method returns a Panel container with a
The two displays we’re using here
class listboxChoice extends multiChoice
class checkBoxChoice extends multiChoice
13
the
getSelected
method
the user selects.of the investmentsreturns a String array
builds.A Builder lets you vary the internal representation of the product it
It also hides the details of how the product is assembled.
program.Each specific builder is independent of the others and of the rest of the
relatively simple.This improves modularity and makes the addition of other builders
that a Builder constructs.depending on the data, you have more control over each final productBecause each builder constructs the final product step-by-step,
A Builder pattern is somewhat like a Factory pattern in that:
the data presented to it.objects, the Builder constructs a complex object step by step depending onThe main difference is that while the Factory returns a family of related