Re: Using abstract class that implements interface
On Sun, 19 Apr 2009, Mark Space wrote:
cbossens73@yahoo.fr wrote:
One of them being that it can make testing *very* difficult.
This.
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...
Abstract base classes are good for providing a common implementation, which
is what the OP has done. But I agree that adding an interface which also
expresses the design is a no-brainer.
At minimum, what happens if you have only a abstract class, and want to add
your API to an existing class, or one that must extend another?
Then you refactor to separate an interface from the base class, which is
trivial to do, with or without a refactoring browser. Why on earth would
you do it before you need to?
The combination of interface and abstract class allows composition,
where the abstract class by itself only allows inheritance.
Great, so if you need to do that, use that combination. But until you do,
don't.
Writing code before you need it is a mistake. It's that simple.
tom
--
curry in a sack