Magic Puzzle (Builder)

zhaozj2021-02-16  48

If a puzzle can be collamed into any graphic. Then we only need to produce a single part of this puzzle. That way

It will make the complex graphics simplistic. This means that we can only use the design of each single step. This is the benefit of this is

What? Obviously. We are using components to produce products. Not need to directly produce a huge product. Because these components

There is versatility. Another benefit is. From complexity with its own. Because it is necessary to produce, it is necessary to assemble.

It will be reduced by the complexity. Then the complexity will be reduced. That is, the so-called dupment. Only do a single consideration, then it provides two

Important functions. One is the Director responsible for the production component is the Director responsible for the combination. This can be responsible

Product decoup.

Then, now we come to simulate the equipment matching problem that often appear in the RPG game. The equipment can be equipped with the hand, his feet. Breastplate

Helmet. So we are now achieving separately, let the following uniform integration.

Interface ibuilder {void builderHand (); void builderfeet (); void bulderhead (); void bulderBody ();

// Appraction of components available 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 actual constructor public class armbuilder: ibuilder {AbstractPart head, feet, body, hand; public void builderhand () {hand = new handpart ();

Public void builderfeet () {feed = new feetpart ();

Public void Buliderhead () {head = new headpart ();

Public void BuliderBody () {body = new bodypart ();

}

// Connectors responsible for assembly

Public class director {

Private ibuilder builder;

Public Director (iBuilder Builder) {this.builder = builder;} public void construct (); builder.buildfoot (); builder.buildbody (); builder.buildbody (); Builder.BuildHand ();}}

Public class client {public static int main (string [] args) {ibuilder builder = new armuilder (); Director Director = New Director; Director.Construct ();

Return 0;}}}

转载请注明原文地址:https://www.9cbs.com/read-27425.html

New Post(0)