Re: Using abstract class that implements interface
- From: Tom Anderson <twic@xxxxxxxxxxxxxxx>
- Date: Sun, 19 Apr 2009 22:47:21 +0100
On Sun, 19 Apr 2009, cbossens73@xxxxxxxx wrote:
On Apr 18, 7:24 pm, Tom Anderson <t...@xxxxxxxxxxxxxxx> 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
.
- Follow-Ups:
- Re: Using abstract class that implements interface
- From: Arved Sandstrom
- Re: Using abstract class that implements interface
- References:
- Using abstract class that implements interface
- From: Zuisman Moshe
- Re: Using abstract class that implements interface
- From: Lew
- Re: Using abstract class that implements interface
- From: Tom Anderson
- Re: Using abstract class that implements interface
- From: cbossens73
- Using abstract class that implements interface
- Prev by Date: Re: Using abstract class that implements interface
- Next by Date: Re: question?
- Previous by thread: Re: Using abstract class that implements interface
- Next by thread: Re: Using abstract class that implements interface
- Index(es):
Relevant Pages
|