程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> My Adapter in C#

My Adapter in C#

編輯:.NET實例教程
//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){}
}
};
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved