Presentation is loading. Please wait.

Presentation is loading. Please wait.

Design Pattern : Builder SPARCS 04 고윤정. Main Concepts One of Creational Patterns. Process to construct Complex object in Abstract type. –Use the same.

Similar presentations


Presentation on theme: "Design Pattern : Builder SPARCS 04 고윤정. Main Concepts One of Creational Patterns. Process to construct Complex object in Abstract type. –Use the same."— Presentation transcript:

1 Design Pattern : Builder SPARCS 04 고윤정

2 Main Concepts One of Creational Patterns. Process to construct Complex object in Abstract type. –Use the same creation process for different representation; type. Director controls all steps of Object creation.

3 Participants & Collaborations Constructs an Object of Concrete type (ConcreteBuilder Class) Parameter of Abstract type (Builder Interface) Director Product Controls all the Process to Construct an Instance

4 Why do we use Builder? Common manner to Create an Instance –Constructor! –Each Parts determined by Parameter of the Constructor public class Room { private int area; private int windows; public String purpose; Room() { } Room(int newArea, int newWindows, String newPurpose){ area = newArea; windows = newWindows; purpose = newPurpose; } There are Only 2 different ways to Create an Instance part-by-part.

5 Why do we use Builder? In the previous example, –We can either determine all the arguments or determine nothing and just construct. We can’t determine arguments partially. –We can’t control whole process to Create an instance. –Restriction of ways to Create an Object ☞ Bad Abstraction & Flexibility

6 Why do we use Builder? Another way to Create an Instance –Member Methods!! –Objects are initially constructed by Default Constructor. –Member Methods modify constructed Instance part-by-part.

7 Why do we use Builder? public class Room { private int area; private int windows; public String purpose; Room() { } public setArea(int newArea){ area = newArea; } public setWindows(int newWindows) { windows = newWindows; } public setPurpose(String newPurpose) { purpose = newPurpose; } public class Client { // … public constructRoom () { Room aRoom = Room(); aRoom.setArea(5); aRoom.setPurpose(“baby”); } Partial determination of Arguments Constructor’s Simplified. - Do nothing but construct.

8 Why do we use Builder? In the previous example, –We can control whole process to Create an instance. –But then the Client is concerned about Concrete Process of Creating an Instance. ☞ Bad Encapsulation & Abstraction So we make a concept, Director –which controls the fine process of Instance Creation –which separates client & process, construction & representation.

9 Collaborations Builder –Provides the Abstract Interface for creating Parts of a Product object. –Information Director received. ConcreteBuilder –Provides the Concrete type (class). –Actual participant which Constructs the Parts of a Product object. –Information Client sends.

10 Collaborations Client –Constructs Product Object by Default Constructor. Determines the Concrete Type of Product. (Creates desired Builder object; ConcreteBuilder) Do nothing about setting the arguments. –Constructs Director Object and configures it with desired Builder Object. Give Director empty Product Object by Parameter. The Object is of Concrete Type, but Director gets an Object of Abstract Type. –Do nothing about the process of Product Creation. –Gets the final result Product (Instance) when Director finishes its work creating.

11 Collaborations Director –Gets empty Object(to be a Product) by Parameter. Whatever the Type of Product Client sent, Director receives by Abstract Interface. Director doesn’t have to concern about Concrete type of the Product Object. –Notifies the Builder whenever a Part of the Product should be built. –Control the whole Process to Create Product part-to-part.

12 Discussion Uses Of Builder –Parsing Program(RTF converter) –GUI


Download ppt "Design Pattern : Builder SPARCS 04 고윤정. Main Concepts One of Creational Patterns. Process to construct Complex object in Abstract type. –Use the same."

Similar presentations


Ads by Google