Design pattern Construction (Builder) Model Building House case Analysis _java

Source: Internet
Author: User
The construction model is mainly used for the production of complex products, the separation of the details of the components to achieve good scalability.
Considering that design patterns originate in architecture, this is an example of building a house. Now a client is going to build a house,
Copy Code code as follows:

public class house{
Customer demand for the house
}

Then he needs a designer-designer, but the designer can only do the design, indicating how to build the house, but he does not do it himself, then need a construction team Buildteam, then first of all, Designer to design how to build this House, First the construction team to play the foundation, then the construction team to frame, and then cement and so on (specifically how unknown, need to consult professionals), then from here we can know that the designer of the construction team is required, that is, the construction team must play the foundation, will frame skeleton, cement and so on, Therefore, the following requirements for recruiting construction teams are as follows:
Copy Code code as follows:

public interface buildteam{
public void Foundation ();
public void frame skeleton ();
public void on cement ();
。。。。。。
}

From the above can be seen, to do this project construction team, must first sign the above conditions, will do all the above things. According to the designer's design, also learned that the designer will give a command to the construction team, and then the construction team in accordance with the requirements of the designers began construction:
Copy Code code as follows:

public class designer{
public void construct (Buildteam) {
Team. Foundation ();
Team. Frame skeleton ();
Team. On cement ();
}
}

Since all the designers have been instructed to design from beginning to end, the construction team to carry out the actual construction, so the customer will eventually find construction team acceptance of the house, so the construction team must deliver the house to the customer, so the construction team needs to add a delivery of the terms of the House, otherwise the house was made, but the construction team did not deliver to me, it is not
Copy Code code as follows:

public interface buildteam{
public void Foundation ();
public void frame skeleton ();
public void on cement ();
。。。。。。
Public house Deliverhouse (); Add a way to deliver a house.
}

Well, the house design is good, how to do also design well, now to who to do, now has a construction team:
Copy Code code as follows:

public class Buildteama extends buildteam{
public void Hit Foundation () {}
public void frame skeleton () {}
public void on cement () {}
。。。。。。
Public house Deliverhouse () {}
}

From the construction team situation, the construction team fully meet the requirements of the construction team, both interface Buildteam, good, then the final decision by them to do, from beginning to end the entire process is as follows:
Designer Designer = new Designer (); Find a designer
Buildteam TeamA = new Buildteama (); Find a construction team Buildteama
Designer.construct (TeamA); The architect ordered the construction team to start building according to his design.
House House = Teama.deliverhouse (); Delivery of the House upon completion of the construction team
The first house was finally built, at this time the same customer thought the design of the designer is good, so decided to use his design and he instructed the construction team to recreate a similar house, but the construction team Buildteama suddenly everytime, want more money, customers in order to save costs, Had to recruit a new construction team to carry out construction, just have a construction team buildteamb meet the requirements, so the process is as follows:
Copy Code code as follows:

Buildteam teamb = new Buildteamb ();
Designer.construct (TEAMB); Because the designer has not changed, and made the same house, so designer do not need to find again, just to the construction team he instructed to replace Buildteamb can
House House = Teamb.deliverhouse (); Delivery of the House upon completion of the construction team

Well, the second house is finished, too. But there is not much change in the process, because the use of the construction model, the whole process of division of labor is very clear, the customer does not need to participate in any design and construction, the designer is only responsible for the design and command, and the construction team is only responsible for specific implementation details, so that the construction details Can be changed at any time to different construction teams.

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.