什么是界面和抽象类它们之间有什么区别? [英] what is interface and abstract class what is the difference between them?

查看:144
本文介绍了什么是界面和抽象类它们之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提供我能够轻松理解的简单答案?

provide the simple answer that i can easily understand?

推荐答案

抽象类就像一组对象的一般描述,但是这个对象本身不能被制作转换成一个真正有意义的对象。



例如,一个Shape的类太抽象而且没有很好地定义成一个对象,但所有形状都有变量和动作类似。



An abstract class is like a general description of a group of objects but this object itself cannot be made into a real meaningful object.

For example a class for Shape it too abstract and not well defined to make into an object, but all shapes will have variables and actions that are similar.

class Shape
{
//variables
int nSides;
bool isRegular;
//methods
double GetArea();
double GetPerimeter();
//void Draw();
}





而不是在类Shape中放置void Draw(),它可以在IDrawable接口中定义。

那么它可能是一个用于任何类型的图形对象的动作。





Instead of putting void Draw() in class Shape, it could be defined in an interfaces IDrawable.
Then it could be an action used for any kind of graphical object.

interface IDrawable
{
void Draw();
}





那么像Square这样的具体类就是可绘制的Shape。



So then a concrete class like Square would be a Shape that is Drawable.


这是一个完整的解释。



抽象类与接口 [ ^ ]



此处:

http://msdn.microsoft.com/en-AU/library/k535acbf(v = vs.71)的.aspx [< a href =http://msdn.microsoft.com/en-AU/library/k535acbf(v=vs.71).aspx\"target =_ blanktitle =New Window> ^ ]
This is a complete explanation.

Abstract Class versus Interface[^]

Also here:
http://msdn.microsoft.com/en-AU/library/k535acbf(v=vs.71).aspx[^]


参考: abstract-class-vs-interface [ ^ ]


这篇关于什么是界面和抽象类它们之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆