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.
时间: 2024-11-09 00:49:44