The most important difference between abstract class and interface is what they are trying to describe.The class is to show : what is it. It's trying to describe the attributes of objects.but the interface is to demonstrate : what can it do. It's trying to describe the functions of objects.I suggest you to look some books about UML, they will give you more useful information about such difference.In coding, The interface can implements multi-inheritance. The abstract class can have attributes.
You’ll learn that the interface is more than just an abstract class taken to the extreme, since it allows you to perform a variation on C++’s “multiple inheritance,” by creating a class that can be upcast to more than one base type. Keep in mind that the core reason for interfaces is shown in the above example: to be able to upcast to more than one base type. However, a second reason for using interfaces is the same as using an abstract base class: to prevent the client programmer from making an object of this class and to establish that it is only an interface. This brings up a question: Should you use an interface or an abstract class? An interface gives you the benefits of an abstract class and the benefits of an interface, so if it’s possible to create your base class without any method definitions or member variables you should always prefer interfaces to abstract classes. In fact, if you know something is going to be a base class, your first choice should be to make it an interface, and only if you’re forced to have method definitions or member variables should you change to an abstract class, or if necessary a concrete class.
class A implements interface001,interface002,interface003
{
......
}
★★ 签名 ★
================================================================
我不能随波浮沉
为了我挚爱的亲人
再苦再累也要坚强
只为那些期待眼神···
如果这是个接口,你implements了它以后还可以extends其他的类.谢谢
It's trying to describe the attributes of objects.but the interface is to demonstrate : what can it do.
It's trying to describe the functions of objects.I suggest you to look some books about UML,
they will give you more useful information about such difference.In coding,
The interface can implements multi-inheritance.
The abstract class can have attributes.
You’ll learn that the interface is more than just an abstract class taken to the extreme, since it allows you to perform a variation on C++’s “multiple inheritance,” by creating a class that can be upcast to more than one base type. Keep in mind that the core reason for interfaces is shown in the above example: to be able to upcast to more than one base type. However, a second reason for using interfaces is the same as using an abstract base class: to prevent the client programmer from making an object of this class and to establish that it is only an interface. This brings up a question: Should you use an interface or an abstract class? An interface gives you the benefits of an abstract class and the benefits of an interface, so if it’s possible to create your base class without any method definitions or member variables you should always prefer interfaces to abstract classes. In fact, if you know something is going to be a base class, your first choice should be to make it an interface, and only if you’re forced to have method definitions or member variables should you change to an abstract class, or if necessary a concrete class.