using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//组合接口
//1.通过组合接口不仅可以在语义上相关多个接口组合成单个接口,还可以在需要时将方法添加进新的组合接口
namespace InterfaceApp
{
public class Control
{
}
public interface IDragDrop
{
void Drag();
void Drop();
}
public interface ISerializable
{
void Serialize();
}
//将IDragDrop,ISerializable组成一个接口ICombo
public interface ICombo : IDragDrop, ISerializable
{
}
public class MyTreeView : Control, ICombo
{
public void Drag()
{
Console.WriteLine("MyTreeView.Drag called");
}
public void Drop()
{
Console.WriteLine("MyTreeView.Drop called");
}
public void Serialize()
{
Console.WriteLine("MyTreeView.Serialize called");
}
}
class Program
{
static void Main(string[] args)
{
MyTreeView tree = new MyTreeView();
tree.Drag();
tree.Drop();
tree.Serialize();
Console.ReadKey();
}
}
}
接口(二):组合接口
最新推荐文章于 2021-07-03 23:42:54 发布