//myabstractfactory
using system;
///////////////basic products////////////////
//abstractproducts
abstract class fontsstyle
{
public string stylestring;
};
abstract class tablesstyle
{
public string stylestring;
};
//realproducts
class fontsstylea:fontsstyle
{
public fontsstylea(){stylestring="fontsstylea";}
};
class fontsstyleb:fontsstyle
{
public fontsstyleb(){stylestring="fontsstyleb";}
};
class tablesstylea:tablesstyle
{
public tablesstylea(){stylestring="tablesstylea";}
};
class tablesstyleb:tablesstyle
{
public tablesstyleb(){stylestring="tablesstyleb";}
};
//////////////basic products////////////////
//////////////style factorys////////////////
abstract class stylefactory
{
abstract public fontsstyle createfontsstyle();
abstract public tablesstyle createtablesstyle();
};
class stylea:stylefactory
{
override public fontsstyle createfontsstyle()
{
return new fontsstylea();
}
override public tablesstyle createtablesstyle()
{
return new tablesstylea();
}
};
class styleb:stylefactory
{
override public fontsstyle createfontsstyle()
{
return new fontsstyleb();
}
override public tablesstyle createtablesstyle()
{
return new tablesstyleb();
}
};
//////////////style factorys////////////////
//////////////////////homepage is the product as last
class homepage
{
private fontsstyle fontsstyle;
private tablesstyle tablesstyle;
private string htmlcode="<html><body><table style=tablesstyle><tr><td><font style=fontsstyle>helloworld!</font></td></tr></table></body></html>";
public homepage(stylefactory stylefactory)
{
fontsstyle=stylefactory.createfontsstyle();
tablesstyle=stylefactory.createtablesstyle();
htmlcode=htmlcode.replace("fontsstyle",fontsstyle.stylestring);
htmlcode=htmlcode.replace("tablesstyle",tablesstyle.stylestring);
}
public void printhtmlcode()
{
console.writeline(htmlcode);
}
public void setstyle(string filename)
{
}
};
//myabstractfactory app
class testapp
{
public static void main( string[] args )
{
stylefactory stylea=new stylea();
homepage samplepage=new homepage(stylea);
samplepage.printhtmlcode();
stylefactory styleb=new styleb();
samplepage=new homepage(styleb);
samplepage.printhtmlcode();
while(true){}
}
};
