Magic puzzle (builder)

Source: Internet
Author: User

 

If a piece of puzzle can be combined into any image, we only need to produce a single part of the puzzle.

This will simplify complex graphics. That is to say, we only need to design every single step. What are the benefits of doing so?

? Obviously, we are using components to produce products, instead of directly producing a huge product, because these components may

It is universal. The other advantage is that it comes from its own complexity. Because production requires assembly, and production and group

The complexity will be reduced. That is, the so-called solution even. We only need to consider a single one, so here we provide two

One is the builder responsible for producing components, and the other is the ctor responsible for combination.

Product solution.

Now, we can simulate the equipment matching problem that often occurs in RPG games. The equipment that a character can be equipped with is the guard hand, foot guard, and chest armor.

Helmet. Now let's implement it separately, and then integrate it in a unified manner.

Interface ibuilder {
Void builderhand ();
Void builderfeet ();
Void buliderhead ();
Void buliderbody ();
}

// Components available for Production
Abstract class abstractpart {
String partname;
}

Class feetpart: abstractpart {
Feetpart (){
Console. writeline ("the part is feet ");
}
}

Class bodypart: abstractpart {
Bodypart (){
Console. writeline ("the part is body ");
}
}

Class headpart: abstractpart {
Headpart (){
Console. writeline ("the part is head ");
}
}

Class handpart: abstractpart {
Handpart (){
Console. writeline ("the part is hand ");
}
}

// Construct the actual Constructor
Public class armbuilder: ibuilder {
Abstractpart head, feet, body, hand;

Public void builderhand (){
Hand = new handpart ();
}

Public void builderfeet (){
Feet = new feetpart ();
}

Public void buliderhead (){
Head = new headpart ();
}

Public void buliderbody (){
Body = new bodypart ();
}

}

// The integrator is responsible for assembly

Public class director {

Private ibuilder builder;

Public Director (ibuilder builder ){
This. Builder = builder;
}
  
Public void construct (){
Builder. buildfoot ();
Builder. buildhead ();
Builder. buildbody ();
Builder. buildhand ();
}
}

Public class client
{
Public static int main (string [] ARGs)
{
Ibuilder builder = new armbuilder ();
Director dire= new director (builder );

Director. Construct ();

Return 0;
}
}

 

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.