码迷,mamicode.com
首页 > 其他好文 > 详细

abstract class and interface

时间:2016-12-11 10:19:40      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:bre   extends   contract   code   abstract   ace   sep   nts   tip   

Interface separates what a Class does and how does it work. List interface lets different type of List to implement its own method.

interface has more flexibility. A class can implements multiple interfaces but can only extends one class.

once interface is implemented by Class, we can not change interface, otherwise, we will break existing code. so interface is like "contract". For 

abstract class, we can still add behavior without breaking existing code.

abstract class allows default implementation. In my project of tweet sentiment analysis, I use Classifier abstract class and in classify_many(), it 

has default implementation but leaves any class that extends it to implement their own classify() method.

abstract class and interface

标签:bre   extends   contract   code   abstract   ace   sep   nts   tip   

原文地址:http://www.cnblogs.com/touchdown/p/6159036.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!