Re: Using abstract class that implements interface
On Sun, 19 Apr 2009, cbossens73@yahoo.fr wrote:
On Apr 18, 7:24 pm, Tom Anderson <t...@urchin.earth.li> wrote:
'Programming to an interface' does *not* refer to the syntactic
construct of an interface, but the semantic idea of a set of defined,
public methods. What in Smalltalk would be called a 'protocol'. An
abstract base class can define an interface for this purpose just as
well as an interface (IYSWIM).
I strongly disagree with this.
In Java it is adviced for a lot of reason to "program to
a Java interface".
Abstract classes are a bad choice for a lot of reason. One
of them being that it can make testing *very* difficult.
Aha, interesting.
I value testing above all else and it's been my personal
experience --and that of many others-- that abstract classes
simply cause too many problems, e.g. when trying to do mock
testing
If the base class is something that needs to be mocked for testing, and
the mock can't conveniently be constructed as a subclass, then that's a
perfectly good reason to refactor out an interface.
and when trying to reach 100% code coverage by test.
How so?
It is true that an OO interface can be defined in Java both by using a
Java interface of a Java "class" (either abstract or not), but the
latter is often poor design...
Often, perhaps - sometimes, certainly. But the point that seems to be lost
on many people here is that it isn't *always* poor design.
tom
--
curry in a sack