The Builder pattern Shuanghui Luo. Type & intent One of the Creational PatternOne of the Creational Pattern Intent:Intent:  Separates the construction.

Slides:



Advertisements
Similar presentations
Creational Patterns (2) CS350/SE310 Fall, Lower the Cost of Maintenance Economic Goal Coupling-Cohesion, Open-Close, Information-Hiding, Dependency.
Advertisements

Creational Patterns, Abstract Factory, Builder Billy Bennett June 11, 2009.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Creational Patterns - Page L4-1 PS95&96-MEF-L11-1 Dr. M.E. Fayad Creationa l Paradigm.
Let’s hear it for BUILDER!!!!!!!. Builder – The Intent \ Description To separate the construction of a complex object from its representation so that.
Software Design & Documentation – Design Pattern: Command Design Pattern: Command Christopher Lacey September 15, 2003.
Design Pattern Course Builder Pattern 1 Mahdieh Monzavi AmirKabir University of Technology, Department of Computer Engineering & Information Technology.
Object-Oriented Enterprise Application Development J2EE Blueprints.
Design Patterns I 1. Creational Pattern Singleton: intent and structure Ensure a class has one instance, and provide a global point of access to it 2.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Builder A Creational Design Pattern A Presentation by Alex Bluhm And.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Design Patterns OOD. Course topics Design Principles UML –Class Diagrams –Sequence Diagrams Design Patterns C#,.NET (all the course examples) Design Principles.
CS 4240: Bridge and Abstract Factory Readings:  Chap. 10 and 11 Readings:  Chap. 10 and 11.
02 - Behavioral Design Patterns – 2 Moshe Fresko Bar-Ilan University תשס"ח 2008.
Case Studies on Design Patterns Design Refinements Examples.
Abstract Factory Design Pattern making abstract things.
Factory Method A Creational Design Pattern. Factory Method Key Features  Defines an interface for creating objects without needing to know each object’s.
Design Pattern Course Builder Pattern By : Sajjad Zare Teacher : Dr. Noorhosseini By: Sajjad Zare 1Design Pattern.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns III.
Software Components Creational Patterns.
Strategy Design Patterns CS 590L - Sushil Puradkar.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Define an interface for creating an object, but let subclasses decide which class to instantiate Factory Method Pattern.
CDP-1 9. Creational Pattern. CDP-2 Creational Patterns Abstracts instantiation process Makes system independent of how its objects are –created –composed.
C# and Design Patterns Builder Pattern. 2 C# and Design Patterns Builder Pattern Object creational pattern Object creational pattern Separates construction.
Define an interface for creating an object, but let subclasses decide which class to instantiate.
1 More OO Design Patterns CSC 335: Object-Oriented Programming and Design.
Builder An Object Creational Pattern Tim Rice CSPP51023 March 2, 2010.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Manali Joshi1 The Observer Design Pattern Presented By: Manali Joshi.
Creational Pattern: Builder When a complex object needs to be created, it is sometimes beneficial to separate the construction of the object from its.
Advanced Object-oriented Design Patterns Creational Design Patterns.
The Facade Pattern (Structural) ©SoftMoore ConsultingSlide 1.
CSC 480 Software Engineering Lab 5 – Abstract Factory Pattern Oct 30, 2002.
Singleton Pattern Presented By:- Navaneet Kumar ise
1 More OO Design Patterns CSC 335: Object-Oriented Programming and Design.
07 - Creational (3)CSC4071 Builder Separate the construction of a complex object from its representation so that the same construction process can create.
Reference – Object Oriented Software Development Using Java - Jia COP 3331 Object Oriented Analysis and Design Chapter 10 – Patterns Jean Muhammad.
Design Pattern: Builder Timothy Holper. The Builder design pattern: What is it? The Builder pattern is a way to: ‘Separate the construction of a complex.
Overview of Creational Patterns ©SoftMoore ConsultingSlide 1.
STRATEGY PATTERN By Michelle Johnson. BACKGROUND Behavioral Pattern Allow you to define a family of algorithms, encapsulate each one, and make them interchangeable.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
Abstract Factory Pattern Jiaxin Wang CSPP Winter 2010.
Design Pattern : Builder SPARCS 04 고윤정. Main Concepts One of Creational Patterns. Process to construct Complex object in Abstract type. –Use the same.
Creational Patterns C h a p t e r 3 – P a g e 14 Creational Patterns Design patterns that deal with object creation mechanisms and class instantiation,
Builder Introduction. Intent Separate the construction of a complex object from its representation so that the same construction process can create different.
1 Creational Design Patterns CSC 335: Object-Oriented Programming and Design.
Strategy Design Pattern
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Design Pattern Catalogues
Design Patterns Lecture part 2.
Factory Patterns 1.
Observer Design Pattern
Software Design and Architecture
object oriented Principles of software design
Creational Patterns (2)
Presented by Igor Ivković
Informatics 122 Software Design II
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Strategy Design Pattern
Design pattern Lecture 6.
Creational Patterns.
Informatics 122 Software Design II
Presented by Igor Ivković
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

The Builder pattern Shuanghui Luo

Type & intent One of the Creational PatternOne of the Creational Pattern Intent:Intent:  Separates the construction of a complex object from its representation so that the same construction process can create different representations.

Applicability The Builder pattern assembles a number of objects in various ways depending on the data.The Builder pattern assembles a number of objects in various ways depending on the data. Use the Builder pattern whenUse 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.

Structure (UML Model) the complex object the complex object under construction. construct an object construct an object using the Builder interface constructs constructs and assembles parts of the product by implementing the Builder interface specifies an abstract specifies an abstract interface for creating parts of a Product object

Builder: specifies an abstract interface for creating parts of a Product object.Builder: specifies an abstract interface for creating parts of a Product object. ConcreteBuilder: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.Director: constructs an object using the Builder interface. Product: represents the complex object under construction.Product: represents the complex object under construction. Participants

Consequences Abstracts the construction implementation details of a class type. It lets you vary the internal representation of the product that it builds.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.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.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.Each specific Builder is independent of any others.

Example (1) A fathers-sons chooserA 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 sons>3  A JPanel with JCheckBoxes, if sons<=3

Example (2)

Example (3) public class MainJPanel extends JPanel implements javax.swing.event.ListSelectionListener { … public void valueChanged(javax.swing.event.ListSelectionEvent e) { … this.getSonsPanel().add(this.getCDirector().getChoiceUI(v)); this.getSonsPanel().validate(); this.getSonsPanel().repaint(); } … } Get one of the GUIs

Example (4) public class ChoiceDirector {… public javax.swing.JPanel getChoiceUI(java.util.Vector choices) { ChoiceAbstractBuilder p; if (choices.size() <= 3) { p= new CheckBoxChoiceConcreteBuilder(choices); }else{ p= new ListChoiceConcreteBuilder(choices); p= new ListChoiceConcreteBuilder(choices);} return p.getGUI(); }…} The abstract builder Concrete builders Builds GUI

References konstanz.de/studium/ze/cim/projekte/osefa/patterns/builder/intent.ht mhttp:// konstanz.de/studium/ze/cim/projekte/osefa/patterns/builder/intent.ht m er.htmlhttp:// er.html