abstract class and interface

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.

posted on 2016-12-11 09:10  touchdown  阅读(86)  评论(0编辑  收藏  举报

导航