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

My FactoryMethod in C#

編輯:.NET實例教程

//MyFactoryMethod
using System;
using System.Collections;
//SinglePage class,which build the at last product,part element
//----top class
abstract class SinglePage
{
};
//----element1
class RegisterPage:SinglePage
{
};
//----element2
class LoginPage:SinglePage
{
};
//----element3
class IndexPage:SinglePage
{
};
//----element4
class TitlePage:SinglePage
{
};
//----element5
class ContentPage:SinglePage
{
};
//----element6
class PostPage:SinglePage
{
};
//----element7
class ReplyPage:SinglePage
{
};
//----------------------------------------------end of Page class
//HomePage class,FactoryMethod is in this class,creater
//----top class
abstract 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();
};
//----concreteclass1
class Forum:HomePage
{
override public void CreateHomePage()
{
Pages.Add(new RegisterPage());
Pages.Add(new LoginPage());
Pages.Add(new IndexPage());
Pages.Add(new TitlePage());
Pages.Add(new ContentPage());
Pages.Add(new PostPage());
Pages.Add(new ReplyPage());

}
};
//----concreteclass2
class 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
//Test
class TestApp
{
public static void Main(string[] args)
{
HomePage aforum=new Forum();
HomePage aguestbook=new GuestBook();

foreach(SinglePage singlepage in aforum.Pages)
{
Console.WriteLine("In a forum homepage contians {0}",singlepage);
}

foreach(SinglePage singlepage in aguestbook.Pages)
{
Console.WriteLine("In a guestbook homepage contians {0}",singlepage);
}

while(true){}

}
};

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