0% found this document useful (0 votes)
19 views

Script

Yes

Uploaded by

marlonmontera60
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Script

Yes

Uploaded by

marlonmontera60
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Hello guys, I am John Marlon V.

Montera, a student of Dalubhasaan ng Lungsod ng Lucena


taking up Bachelor of Science in Information Technology. Before I proceed to my discussion,
let me ask you few questions? Do you know creational design pattern? Are you aware that
you are experiencing a certain creational design pattern in your living? I think probably most
of you will say “No”, right. As I proceed, let me define to you first what is a creational design
pattern.

Builder Pattern

Explanation : By employing a builder method, we can avoid including all constructor parameters that
aren't always required to create an object. Rather, we permit this builder method to move the object
construction code to distinct objects known as builders and extract it from its own class. Object
construction is arranged by the pattern into a series of steps (buildWalls, buildDoor, etc.). You use a
builder object and a series of these steps to create an object.

Structure of a Builder Pattern

A director is someone who has the authority to give orders and carry out the building steps, much like a
manager or OIC of a company. The director is in charge of all the builders that are a part of an object.
You can reuse different construction routines throughout your program by placing them in the director
class.
Furthermore, the client code is never made aware of the specifics of the product construction thanks to
the director class. All the client has to do is assign a builder to a director, work with the director to start
construction, and then receive the builder's output.

Example of the Builder Pattern

The goal of the builder pattern is to separate the construction of an object from its representation.

As you can see in this image, there is a class Item in this scenario of pizza hut wherein it has the name
function which is a string, size function which is also a string, and price function which is a float. Object’s
representation of the Item/Pizza/ColdDrink.

Attributes – for example sa house, stories, door type, roof type

Methods to set this field – for example sa house, setStories, setdoortype, and setRooftype

Build:

return new House(self)

House(HouseBuilder) which gets the instance of the class House Builder

Representation yung unang house, tapos yung ikalawa na house builder ay construction.

Separation of construction to its representation in an object is important in builder pattern.


So in this example, we have the base class Item

1. Builder Interface: Define an interface that specifies the steps involved in constructing the object.
Each step may correspond to setting a particular attribute or configuration option.

2. Concrete Builders: Implement concrete builder classes that implement the builder interface and
provide specific implementations for constructing the object. Each concrete builder is
responsible for constructing a particular type of object.

3. Product: Define the object being constructed. This is typically a complex object that requires
multiple steps to be fully initialized.

4. Director: In some implementations, a director class may be used to orchestrate the construction
process. The director class interacts with the builder to initiate the construction steps in a
particular order.

5. The Client must associate one of the builder objects with the director. Usually, it’s done just
once, via parameters of the director’s constructor. Then the director uses that builder object for
all further construction. However, there’s an alternative approach for when the client passes the
builder object to the production method of the director. In this case, you can use a different
builder each time you produce something with the director.

In this tree diagram:

The root node represents the Pizza Hut operation.

The first level contains the PizzaBuilder class, which is responsible for constructing pizzas.

The next level includes the methods of the PizzaBuilder class: addCrust(), addToppings(), setCheese(),
setSauce(), and getPizza().

Finally, the leaf nodes represent the attributes of the Pizza class: crust, toppings, cheese, and sauce.

This diagram visually illustrates how the components of the Pizza Hut operation are structured, with the
PizzaBuilder orchestrating the construction process and the Pizza class representing the final product.

You might also like