Why are the interfaces more flexible than abstract classes?

Q

Why are the interfaces more flexible than abstract classes?

✍: Guest

A

--An interface-defined type can be implemented by any class in a class hierarchy and can be extended by another interface. In contrast, an abstract-class-defined type can be implemented only by classes that subclass the abstract class.
--An interface-defined type can be used well in polymorphism. The so-called interface type vs. implementation types.
--Abstract classes evolve more easily than interfaces. If you add a new concrete method to an abstract class, the hierarchy system is still working. If you add a method to an interface, the classes that rely on the interface will break when recompiled.
--Generally, use interfaces for flexibility; use abstract classes for ease of evolution (like expanding class functionality).

2013-03-06, 2138👍, 0💬