My Builder In C #

zhaozj2021-02-16  107

// mybuilderusing 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> parttable, partspan ";} // 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;}

}

/// product ///// directorclass 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"] = "

";} Override Public Void Buildspan () {HomePage [" span "] =" ";}};

class WormBuilder: PageBuilder {override public void BuildFrame () {homepage = new HomePage ( "wormpage");} override public void BuildTable () {homepage [ "table"] = "

";} Override public void Buildspan () {homepage [" span "] =" ";}}; Class Clearbuilder: PageBuilder {Override Public void buildframe () {homepage = new homepage ("clearpage");} Override public void buildtable () {homepage ["Table"] = "
";} Override public void buildspan () {homepage [" span "] =" ";

/// builder /////

// mybuilder testclass 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) {}

}};

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

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.035, SQL: 9