My Adapter in C#

王朝c#·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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

}

};

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航