程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> My Builder in C#

My Builder in C#

編輯:關於C語言
//MyBuilder
using System;
using System.Collections;

///////////////////////product///////////////////////
class HomePage
{
//FIElds
private string pagetype;
private string samplecode;
private Hashtable parts=new Hashtable();
//Construcrors
public HomePage(string pagetype)
{
this.pagetype=pagetype;
samplecode="<html><body>parttable,partspan</body></Html>";
}
//Indexers
public object this [string key]
{
get{return parts[key];}
set{parts[key]=value;}
}

//Methods
public void PrintHtmlCode()
{
samplecode=samplecode.Replace("parttable",parts["table"].ToString());
samplecode=samplecode.Replace("partspan",parts["span"].ToString());
Console.WriteLine(samplecode);
}

};

///////////////////////product///////////////////////
//////////////////////director////////////////////////
class PageDirector
{
public void Construct(PageBuilder pagebuilder)
{
pagebuilder.BuildFrame();
pagebuilder.BuildTable();
pagebuilder.BuildSpan();
}

};
//////////////////////director////////////////////////
///////////////////////builder///////////////////////
abstract class PageBuilder
{
//FIElds
protected HomePage homepage;
//PropertIEs
public HomePage HomePage
{
get{return homepage;}
}
//Methods
abstract public void BuildFrame();
abstract public void BuildTable();
abstract public void BuildSpan();
}

class CoolBuilder : PageBuilder
{
override public void BuildFrame()
{
homepage=new HomePage("coolpage");
}
override public void BuildTable()
{
homepage["table"]="<table color=cool><tr><td><td></tr></table>";
}
override public void BuildSpan()
{
homepage["span"]="<span color=cool></span>";
}
};

class WormBuilder : PageBuilder
{
override public void BuildFrame()
{
homepage=new HomePage("wormpage");
}
override public void BuildTable()
{
homepage["table"]="<table color=worm><tr><td><td></tr></table>";
}
override public void BuildSpan()
{
homepage["span"]="<span color=worm></span>";
}
};

class ClearBuilder : PageBuilder
{
override public void BuildFrame()
{
homepage=new HomePage("clearpage");
}
override public void BuildTable()
{
homepage["table"]="<table color=clear><tr><td><td></tr></table>";
}
override public void BuildSpan()
{
homepage["span"]="<span color=clear></span>";
}
};


///////////////////////builder///////////////////////

//MyBuilder test
class TestApp
{
public static void Main(string[] args)
{
PageBuilder b1=new CoolBuilder();
PageBuilder b2=new WormBuilder();
PageBuilder b3=new ClearBuilder();

PageDirector pagedirector=new PageDirector();

pagedirector.Construct(b1);
pagedirector.Construct(b2);
pagedirector.Construct(b3);

b1.HomePage.PrintHtmlCode();
b2.HomePage.PrintHtmlCode();
b3.HomePage.PrintHtmlCode();

while(true){}

}
};

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved