Abstract types and interfaces are two mechanisms used to specify programming abstraction. Abstract an agreement that must be followed by a designated successor or implementer. Abstract types can provide implementation details, while interfaces cannot provide any implementation details.
- Classes may only inherit from a base class, so if you want to use abstract classes to provide polymorphism for a group of classes, these classes must all inherit from that class.
- Abstract classes may also provide implemented members. Therefore, you can use abstract classes to ensure that a specified number of functions are the same, but you cannot use interfaces to do so.
Here are some suggestions to help you decide whether to use interfaces or abstract classes to provide polymorphism for components.
- If you want to create multiple versions of a component, create an abstract class. Abstract classes provide a simple way to control component versions. By updating the base class, all inheritance classes are automatically updated with the change. On the other hand, the interface cannot be changed once it is created. If you need a new version of the interface, you must create a new interface.
- If the created function is used across a wide range of different objects, the interface is used. Abstract classes are mainly used for closely related objects, and interfaces are most suitable for providing general functions for irrelevant classes.
- If you want to design small and concise functional blocks, use interfaces. If you want to design a large functional unit, use an abstract class.
- If you want to provide common implemented functions among all the implementations of a component, use an abstract class. Abstract classes allow partial implementation classes, while interfaces do not include the implementation of any member.
Reference: http://msdn.microsoft.com/library/chs/default.asp? Url =/library/CHS/vbcon/html/vbconw.actclassesversusinterfaces. asp