接口VS抽象类
来源:互联网 发布:java实现跨域请求 编辑:程序博客网 时间:2024/06/13 00:03
msdn版:
Here are some recommendations to help you to decide whether to use an interface or an abstract class to provide polymorphism for your components.
- If you anticipate creating multiple versions of your component, create an abstract class. Abstract classes provide a simple and easy way to version your components. By updating the base class, all inheriting classes are automatically updated with the change. Interfaces, on the other hand, cannot be changed once created. If a new version of an interface is required, you must create a whole new interface.
- If the functionality you are creating will be usefulacross a wide range of disparate objects, use an interface. Abstract classes should be used primarily for objects that are closely related, whereas interfaces are best suited for providing common functionality to unrelated classes.
- If you are designing small, concise bits of functionality, use interfaces. If you aredesigning large functional units, use an abstract class.
- If you want to provide common, implemented functionality among all implementations of your component, use an abstract class. Abstract classes allow you to partially implement your class, whereas interfaces contain no implementation for any members.
- Main difference is methods of a Java interface are implicitly abstract and cannot have implementations. A Java abstract class can have instance methods that implements a default behavior
- Variables declared in a Java interface is by default final. An abstract class may contain non-final variables.
- Members of a Java interface are public by default. A Java abstract class can have the usual flavors of class members like private, protected, etc..
- Java interface should be implemented using keyword “implements”; A Java abstract class should be extended using keyword “extends”.
- An interface can extend other Java interface only, an abstract class can extend another Java class and implement multiple Java interfaces.
- A Java class can implement multiple interfaces but it can extend only one abstract class.
- Interface is absolutely abstract and cannot be instantiated; A Java abstract class also cannot be instantiated, but can be invoked if a main() exists.
- In comparison with java abstract classes, java interfaces are slow as it requires extra indirection.
- 接口 vs 抽象类
- 抽象类 vs 接口
- 接口VS抽象类
- 抽象类vs接口
- 抽象类 VS 接口
- 抽象类VS接口
- 抽象类VS接口
- 抽象类VS接口
- 抽象类VS接口
- 抽象类 VS 接口
- 接口 vs 抽象类
- Java 抽象类 vs 接口
- 数组VS枚举;类VS结构;抽象类VS接口
- 抽象类 vs 接口(Java)
- 图说OO--抽象类VS接口
- 【C#】——抽象类VS接口
- 【java学习笔记】接口VS抽象类
- Abstract Class VS Interface | 抽象类VS接口
- 如何让C++ 和 STL 为C服务
- word2
- 我的iphone开发学习笔记(二)使用UITextView, UITextField 和UIButton控件
- vim 文件编码
- VC++中如何删除一个类
- 接口VS抽象类
- STL----vector与string
- 虚拟机三种工作模式(bridged、NAT和host-only)
- js中cookie的基本用法
- Google Guice入门教程3
- SQLunion和union all 的区别
- Twitter Storm入门实战
- 检索com类工厂中CLSID为{0002E55D-0000-0000-C000-000000000046}的组件失败,原因是出现以下错误:8004015
- 热血江湖游戏窗口化的方法