欢迎光临
我们一直在努力

My AbstractFactory in C#-.NET教程,C#语言

建站超值云服务器,限时71元/月

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

}

};

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » My AbstractFactory in C#-.NET教程,C#语言
分享到: 更多 (0)

相关推荐

  • 暂无文章