软件开发方法--.NET基于接口的编程 Interface first programming
为了创建高质量的可维护性,可重用性,可扩展性的应用程序,通常我们使用面向对象的抽象设计。这其中我们可以使用面向对象语言C#提供的abstract class抽象类和interface接口。
1.Interface接口支持多继承:
1
public interface ICpu
2
{
3
//![](https://www.cnblogs.com/Images/dot.gif)
4
}
5![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
public interface IMemory
7
{
8
//![](https://www.cnblogs.com/Images/dot.gif)
9
}
10![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
public interface IComputer : ICpu, IMemory
12
{
13
//![](https://www.cnblogs.com/Images/dot.gif)
14
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
2.接口是对实体的完全抽象:
在下面的方法中使用接口Interface作为参数,那么任何实现这个接口的对象都可以作为参数。
1
public void MakeComputer(IComputer computer)
2
{
3
//![](https://www.cnblogs.com/Images/dot.gif)
4
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
基于以上观点,我认为可以从两方面分析:
1. 首先分析抽象类和接口所具有特性,也就是在技术层面。
2. 另一方面就是结合你的业务对象所具有的行为,也就是在业务逻辑层面。
http://msdn2.microsoft.com/en-us/library/scsyfw1d(vs.71).aspx