Builder mode of design mode Learning (Builder, Creation Mode) (6)

Source: Internet
Author: User

If we need to build a house, and we don't know how to build a house, we will find someone else to help us build a house.

Step 1:

Create a new House class House with the property of the House. Let's find the House builder interface HouseBuilder. If we want to build a bungalow, we will find PingFangHouseBuilder, which inherits from HouseBuilder, there are various methods to build a house, such as floor makeFloor and wall makeWall.

Step 2:

It's not enough for someone who can build a house. We need a dedicated designer, housedire, to call the house building method.

Step 3:

The customer only knows how to build a bungalow. He can only ask the designer to call the builder to build the house and then get the house from the builder.

The Code is as follows:

House. java

              .floor = .wall = .housetop =

HouseBuilder. java

                

PingFangHouseBuilder. java

  House house =    

HouseDirector. java

      

MainClass. java

           HouseBuilder houseBuilder = = =

1. What is the builder model?

The Builder mode is also called the Builder mode or Builder mode. It is one of the 23 design modes proposed by GoF. Builder mode is one of the object creation modes. It is used to hide the process of creating a composite object. It abstracts the process of creating a composite object and uses subclass inheritance and overloading, dynamically create objects with composite attributes.

II. Application scenarios of builder Mode

-Object creation: the Builder mode is designed for object creation.

-Create a composite object: The created object is a composite object with composite attributes.

-Follow the creation process of each part of an object: different factories (builder here) have different methods to create product properties.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.