Properties2 extends Hashmap, pros and cons?
/snip/
You're probably exactly right about that. The implementor saw
some apparent similarities and decided to reuse the code. A better
approach would have been to design an interface for Properties
and an abstract implementation AbstractProperties that internally
used a Hashtable object (thus getting the code reusability he
wanted in the first place). A factory class would dispense
objects that implement the Properties interface that would
protect client code from becoming dependent upon the actual
implementation details.
Other languages, like Eiffel, would allow a private inheritance
of a Hashtable implementation so that client code could not
up-cast the object and use it like a Hashtable. However, that's
not the case for Java, so object composition would have been
a better choice than inheritance.
|