My FactoryMethod in C #

zhaozj2021-02-16  113

// MyFactoryMethodusing System; using System.Collections; // SinglePage class, which build the at last product, part element // ---- top classabstract class SinglePage {}; // ---- element1class RegisterPage: SinglePage {}; // ---- Element2Class LoginPage: SinglePage {}; // ---- Element3class IndexPage: SinglePage {}; // ---- Element4class Titlepage: SinglePage {}; // ---- Element5class ContentPage: SinglePage { }; // ---- Element6class Postpage: SinglePage {}; // ---- Element7class replypage: Singlepage {}; // ------------------------------------------------------------------------------------------------ -------------------------- End of page Class // Home Class, FactoryMethod Is in this class, creater // --- top classabstract class HomePage {// Fields, the aim page data protected ArrayList pages = new ArrayList (); // Properties public ArrayList Pages {get {return pages;}} // Methods public HomePage () {this.CreateHomePage ();}

abstract public void CreateHomePage ();}; // ---- concreteclass1class Forum: HomePage {override public void CreateHomePage () {Pages.Add (new RegisterPage ()); Pages.Add (new LoginPage ()); Pages.Add (new indexpage ()); pages.add (new contentpage ()); pages.add (new postd (new replypage ());}} // ---- concreteclass2class GuestBook: HomePage {override public void CreateHomePage () {Pages.Add (new RegisterPage ()); Pages.Add (new LoginPage ()); Pages.Add (new ContentPage ()); Pages. Add (new replypage ());}}; // ------------------------------------- --------- End of homepage class // testclass testapp {public static void main (string [] args) {homepage AFORUM = New forum (); HomePage agureBook = New guestbook ();

Foreach (SinglePage Singlepage In Aforum.pages) {Console.WriteLine ("IN a forum homepage contrans {0}", singlepage);

Foreach (SinglePage Singlepage In Aguestbook.pages) {Console.Writeline ("in a guestbook homepage contrans {0}", singlepage);} while (true) {}

}};

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

New Post(0)