Dota design model-Builder

Source: Internet
Author: User
Builder mode. A series of methods are provided to process the product. You can select any combination of methods, but you must write the builder mode. Code Strong business knowledge is required. Finally, you can get the corresponding product.
UML diagram:

The UML diagram shows that the builder contains the product construction and acquisition. The ctor wizard determines how to build the product.
For Model Construction In Dota, You need to implement the following interface ibuilder, including creating models, adding names, setting skills, and textures. If you are not interested in the list, you can complete it yourself.
Internal   Interface Ibuilder
{
Void Createmodel ();
Void Addname ();
Void Setskill ();
Void Maps ();
}
The main character is our builder. The model object is instantiated in the constructor, which contains all the construction processes in ibuilder. For the model class, see the complete code.
Public   Class Modelbuilder: ibuilder
{
Private Model _ model;

PublicModelbuilder ()
{
_ Model= NewModel ();
}

PublicModel GetModel ()
{
Return_ Model;
}

# RegionIbuilder Member

Public void createmodel ()
{< br> _ model. addproperty ( " createmodel " , " createmodel " );
}

Public void addname ()
{< br> _ model. addproperty ( " addname " , " addname " );
}

Public void setskill ()
{< br> _ model. addproperty ( " setskill " , " setskill " );
}

Public VoidMaps ()
{
_ Model. addproperty ("Maps","Maps");
}

# Endregion
}
Test code:
Dotapatternlibrary. Builder. modelbuilder mbobj = new dotapatternlibrary. Builder. modelbuilder ();
Mbobj. createmodel ();
Mbobj. addname ();
Mbobjnew. Maps ();
Dotapatternlibrary. Builder. Model = mbobj. GetModel ();
Model. Show ();
Dotapatternlibrary. Builder. modelbuilder mbobjnew = new dotapatternlibrary. Builder. modelbuilder ();
Mbobjnew. createmodel ();
Mbobjnew. addname ();
Mbobjnew. setskill ();
Mbobjnew. Maps ();
Model = mbobjnew. GetModel ();
Model. Show ();
One in the test code is a number, the other is a hero, and the two build processes are inferior to the setkill method, because the tree does not require skills.
Complete code: Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. text;
Using System. collections;

UsingDotacommon;

namespace dotapatternlibrary. builder
{< br> internal interface ibuilder
{< br> void createmodel ();
void addname ();
void setskill ();
void maps ();
}

Public ClassModelbuilder: ibuilder
{
PrivateModel _ model;

PublicModelbuilder ()
{
_ Model= NewModel ();
}

PublicModel GetModel ()
{
Return_ Model;
}

# RegionIbuilder Member

Public void createmodel ()
{< br> _ model. addproperty ( " createmodel " , " createmodel " );
}

Public void addname ()
{< br> _ model. addproperty ( " addname " , " addname " );
}

Public void setskill ()
{< br> _ model. addproperty ( " setskill " , " setskill " );
}

Public VoidMaps ()
{
_ Model. addproperty ("Maps","Maps");
}

# Endregion
}

Public   Class Model
{
Hashtable htobj =   New Hashtable ();
Internal   Void Addproperty ( String Key, String Value)
{
Htobj. Add (Key, value );
}
Public   Void Show ()
{
Foreach ( String Value In Htobj. values)
{
Landpyform. Form. outputresult (value );
}
}
}
}

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.