附:A Sample
需求:在一个表格(已有的Table类)里面我要显示这样一些数据:
1 文本信息: 显示文本
2 图片信息:显示图片
3 视频信息:播放视频
设计如下:
interface
IDisplayable
{
void Display(Table table);
}
public class Text:IDisplayable
{
public void Display(Table table)
{
//implements the text display method
}
}
public class Picture:IDisplayable
{
public void Disply(Table table)
{
//implements picture display here
}
}
public class Vedio:IDisplayable
{
public void Disply(Table table)
{
//implements vedio play
}
}
public class Test
{
Text t = new Text("Hello");
Picture p = new Picture("1.jpg");
Vedio v = new Vedio("sample.avi");
Table table = new Table();
Table.Add(t);
Table.Add(p);
Table.Add(v);
Table.Show();
foreach(IDisplayable disp in Table.Items)
{
disp.Display(this.table);
}
}
{
void Display(Table table);
}
public class Text:IDisplayable
{
public void Display(Table table)
{
//implements the text display method
}
}
public class Picture:IDisplayable
{
public void Disply(Table table)
{
//implements picture display here
}
}
public class Vedio:IDisplayable
{
public void Disply(Table table)
{
//implements vedio play
}
}
public class Test
{
Text t = new Text("Hello");
Picture p = new Picture("1.jpg");
Vedio v = new Vedio("sample.avi");
Table table = new Table();
Table.Add(t);
Table.Add(p);
Table.Add(v);
Table.Show();
foreach(IDisplayable disp in Table.Items)
{
disp.Display(this.table);
}
}