Re: Using abstract class that implements interface



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
.



Relevant Pages

  • Re: why does catching errors that arent thrown give syntax errors?
    ... The interface has methods that were added in Java 6, so the code doesn't compile under Java 6. ... public interface Statement40 extends Statement30 ... Another option might be to have an abstract base class for implementing the interface, which has concrete stubs for all the methods, so that as long as you extend that, you conform to the interface even as it changes, because when the interface is expanded, so is the base class. ...
    (comp.lang.java.programmer)
  • Re: Darkroom software Help
    ... Apple's computer operating system OS-X includes the Java ... programing language, compiler, and integration software. ... have an Apple this fall. ... Said that, my system is based on a commercial lab interface, the ...
    (rec.photo.darkroom)
  • Re: VM complexity curves...
    ... support to an app without having to drag around zlib or libjpeg, ... (overly monolithic, awkward to interface with, ...). ... I ended up not using the GC for most of my compiler stuff, ... using a standard Java compiler offers no real ...
    (comp.lang.misc)
  • Re: A C++ Whishlist
    ... with the C++ string classes as compared with the Java ones. ... You can keep you structs entirely ... The simple separation of interface and implementation that header files ...
    (comp.lang.cpp)
  • Stuff the purple heart programmers cook up
    ... C To act like a framework for the JDBC driver developers. ... D To hide the specifics of accessing particular kinds of database ... Topic: Java 2: Survey Author: Chris Mc Devitt ... The JDBC ResultSet is actually an interface java.sql.ResultSet. ...
    (comp.lang.java.programmer)