Re: java inheritance
On 11/11/2013 8:30 AM, asdf9797 wrote:
Hi
I did a java test recently and one of the questions was on the subject of
inheritance/ OO design
The idea was there was a "Storable" abstract class which contained a store() method.
There was a IStorable interface
And then there was
class Book extends Storable implements IStorable {
public void save(Book) {
}
}
The question was how to improve the implementation.
Fixing the syntax error would be a good start ...
What is the current thinking on extending abstract classes ?
The current thinking is that an abstract class that's not
extended is very nearly useless. ;-)
Is that the issue?
I don't know what the test-setters were looking for. Perhaps
the Storable class already implements IStorable, so the "implements"
part in Book is redundant. Maybe they felt the abstract class didn't
add value, and hoped you would discard "extends Storable". It's
possible they wanted the save() method to take any Storable (or
maybe IStorable) instead of insisting on a Book. Possibly all they
wanted was a trivial renaming, something along the lines of
interface Storable { ... }
abstract class AbstractStorable implements Storable { ... }
class Book extends AbstractStorable { ... }
Some design schemes are fairly rigid about such things -- make
an interface with THIS kind of name, and an abstract implementing
class with THAT kind of name, and so on and so on. If the testers
were aficionados of one such scheme, perhaps they were just trying to
find out whether you, too, were familiar with it. I'd say familiarity
with a particular set of conventions is not quite the same thing as
familiarity with Java and/or with O-O design -- but maybe that's not
what they were after.
--
Eric Sosman
esosman@comcast-dot-net.invalid