Creator of design patterns

Source: Internet
Author: User
I haven't written Design Model Study Notes for a long time. Today I am bored. I can write down all my previous models.

FirstCodePost it.

This mode is used to simulate a game of xishanju, which is written by the swordsman. I don't know how the game is designed, put it here as an example.

Using system;
Using system. Collections. Generic;
Using system. text;
Using system. drawing;

namespace builder
{< br> Public interface Map
{< br> path
{< br> get;
set;
}< br> tree
{< br> get;
set;
}

Color maincolor
{
Get;
Set;
}
}
}

Using system;
Using system. Collections. Generic;
Using system. text;

Namespace Builder
{
Public class Changbai Mountains: Map
{

private temproad;
public road
{< br> Get
{< br> return temproad;
}< br> set
{< br> temproad = value;
}< BR >}

private tree temptree;
public tree
{< br> Get
{< br> return temptree;
}< br> set
{< br> temptree = value;
}< BR >}

private system. drawing. color tempmaincolor;
public system. drawing. color maincolor
{< br> Get
{< br> return tempmaincolor;
}< br> set
{< br> tempmaincolor = value;
}< BR >}


}
}

Using system;
Using system. Collections. Generic;
Using system. text;

Namespace Builder
{
Public interface
{
Double width
{
Get;
Set;
}

Double height
{
Get;
Set;
}

System. Drawing. color
{
Get;
Set;
}
}
}

Using system;
Using system. Collections. Generic;
Using system. text;

Namespace Builder
{
Public class cement road: Road
{
# Region route members

Public double width
{< br> Get
{< br> throw new exception ("the method or operation is not implemented. ");
}< br> set
{< br> throw new exception (" the method or operation is not implemented. ");
}< BR >}

Public double height
{< br> Get
{< br> throw new exception ("the method or operation is not implemented. ");
}< br> set
{< br> throw new exception (" the method or operation is not implemented. ");
}< BR >}

public system. drawing. color color
{< br> Get
{< br> throw new exception ("the method or operation is not implemented. ");
}< br> set
{< br> throw new exception (" the method or operation is not implemented. ");
}< BR >}

# Endregion
}
}

Using system;
Using system. Collections. Generic;
Using system. text;

Namespace Builder
{
Public interface tree
{
System. Drawing. color
{
Get;
Set;
}
}
}

Using system;
Using system. Collections. Generic;
Using system. text;

Namespace Builder
{
Public class Wutong tree: Tree
{
# Region tree members

public system. drawing. color color
{< br> Get
{< br> throw new exception ("the method or operation is not implemented. ");
}< br> set
{< br> throw new exception (" the method or operation is not implemented. ");
}< BR >}

# Endregion
}
}

Using system;
Using system. Collections. Generic;
Using system. text;

Namespace Builder
{
Create a public interface Map
{
Void create path ();

Void create tree ();

Void to set the color ();

Map object ();
}
}

Using system;
Using system. Collections. Generic;
Using system. text;

Namespace Builder
{
Public class creating a map in the south of Changbai Mountains: creating a map
{
Private map: Map of the south of Changbai Mountains;
Public creating a map of the South foot of Changbai Mountains ()
{
Map of the South foot of Changbai Mountains = New South foot of Changbai Mountains ();
}

Public void create path ()
{
The road in the south of Changbai Mountains = new cement road ();
Map of the South foot of Changbai Mountains. Road = the road of the South foot of Changbai Mountains;
}

Public void create tree ()
{
Tree in the south of Changbai Mountains = new Wutong tree ();
Map of the South foot of Changbai Mountains. Tree = tree of the South foot of Changbai Mountains;
}

Set public void color ()
{
Map of the South foot of Changbai Mountains. maincolor = system. Drawing. color. White;
}

Public map object ()
{
Return map of the South foot of Changbai Mountains;
}
}
}

Using system;
Using system. Collections. Generic;
Using system. text;

Namespace Builder
{
 

Public Class System
{
Map creation;
Public System (map creation a map creation instance)
{
Map creation = a map creation instance;
}

Create a public map ()
{

Map creation. Create a path ();

Map creation. Create a tree ();

Map creation. Set the color ();

Return map creation. map object ();
}
}


}

Client call:

Builder. System Builder system = new builder. System (New builder. Creating a map of the south of Changbai Mountains ());


Builder. MAP: Map of the South foot of Changbai Mountains = builder system. Create a map ();

I am very worried, according to this practice, how more and more like the factory method.
Well, I don't know if this mode is correct.
Put the code here first, and there is time to study the differences between the creator and the factory method.

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.