首页 > 开发 > 综合 > 正文

My Adapter in C#

2024-07-21 02:19:08
字体:
来源:转载
供稿:网友
//myadapter
using system;
//class1
class simpledrawer
{
//methods
virtual public void setcolor(string name){}
};
//adapter class which enables class1 to use class2 methods
class assistantdrawer:simpledrawer
{
//use the adaptee
professionaldrawer drawer = new professionaldrawer();
//methods
override public void setcolor(string name)
{
//colors
switch(name)
{
case "white":drawer.setcolor(255,255,255);break;
case "black":drawer.setcolor(0,0,0);break;
default:console.writeline("i haven't seen this color!");break;
}
}
};
//class2,adaptee
class professionaldrawer
{
//methods
public void setcolor(int a,int b,int c)
{
console.writeline("set the color to rgb({0},{1},{2})",a,b,c);
}
};

//testapp
class testapp
{
public static void main(string []args)
{
assistantdrawer drawer=new assistantdrawer();
drawer.setcolor("red");
drawer.setcolor("black");
drawer.setcolor("white");
while(true){}
}
};



国内最大的酷站演示中心!
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表