1. Trang chủ
  2. » Công Nghệ Thông Tin

Software design: Lecture 33 - Sheraz Pervaiz

28 4 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Builder Design Pattern
Trường học Not specified
Chuyên ngành Software Design
Thể loại Lecture
Năm xuất bản Not specified
Thành phố Not specified
Định dạng
Số trang 28
Dung lượng 515,27 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Software design - Lecture 33. The main topics covered in this chapter include: builder design pattern; motivation for builder design pattern; intent of builder design pattern; builder pattern; class diagram; sequence diagram; solution in builder design pattern;...

Trang 1

Lecture : 33

Trang 2

Builder Design Pattern

Trang 3

 This  type  of  design  closely  ties  the  object  construction  process with the components that make up the object.

Trang 5

 This design may not be effective when the object being created 

is  complex  and  the  series  of  steps  constituting  the  object  creation  process  can  be  implemented  in  different  ways  producing different representations of the object. 

 Different  implementations  of  the  construction  process  are  all  kept  within  the  object,  the  object  can  become  bulky  (construction bloat) and less modular. Subsequently, adding a  new  implementation  or  making  changes  to  an  existing  implementation requires changes to the existing code.

Trang 7

 Using the Builder pattern, the process of constructing such an  object can be designed more effectively. 

Trang 9

In terms of implementation, each of the different steps in the construction process can be declared 

as  methods  of  a  common  interface  to  be implemented  by  different  concrete  builders  as shown in the class diagram in next slide

Trang 11

Sequence Diagram

Trang 13

Instead  of  having  client  objects  invoke  different builder  methods  directly,  the  Builder  pattern suggests using a dedicated object referred to as a 

Director,  which  is  responsible  for  invoking  different  builder  methods  required  for  the 

construction of the final object

Trang 14

Different  client  objects  can  make  use  of  the Director object to create the required object and once  the  object  is  constructed,  the  client  object can directly request from the builder the fully

   constructed object

Trang 15

A new method getObject can be declared in the common Builder interface to be implemented by different concrete builders

Trang 16

The new design eliminates the need for a client object to deal with the methods constituting the object construction process and encapsulates the details of how the object is constructed from the client

Trang 17

Class Diagram of Improved Version

Trang 19

i The  client  object  creates  instances  of  an  appropriate 

concrete  Builder  implementer  and  the  Director.  The  client  may use a factory for creating an appropriate Builder object.

ii   The  client  associates  the  Builder  object  with  the  Director 

object.

iii   The  client  invokes  the  build  method  on  the  Director 

instance to begin the object creation process. Internally, the  Director  invokes  different  Builder  methods  required  to  construct the final object.

iv  Once the object creation is completed, the client invokes the 

getObject method on the concrete Builder instance to get the  newly created object.

Trang 20

Sequence Diagram

Trang 22

Example of Builder Class

Trang 23

Consider  construction  of  a  home,  Home  is  the final end product (object) that is to be returned 

as the output of the construction process. It will have  many  steps,  like  basement  construction, wall  construction  and  so  on  roof  construction. Finally the whole home object is returned. Here using  the  same  process  you  can  build  houses with different properties

Trang 25

Java Code in Eclipse

Trang 27

Patterns

Ngày đăng: 05/07/2022, 14:06