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