My FactoryMethod in C#
2024-07-21 02:19:39
供稿:网友
//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){}
}
};
,欢迎访问网页设计爱好者web开发。