How to... private inheritance ?!

S

sakis.panou

Hi All,

Let me say thank you to all who took the time to read and respond to
my questions. They have certainly given me a lot of food for thought.

I have been always of the view that a problem can have several
solutions some more appropriate than others (...blatantly obvious
that... ;-) ).

It would be a major understatement to say that I strongly believe in
the Programming to an Interface paradigm. With that in mind, you
mentioned that you can't protect the user from screwing things up in a
rather spectacular manner and I whole heartedly agree with that
statement. But sure as hell I want to make it difficult for them to
screw it up. So the question goes against how much effort you want to
invest to achieve that? I guess a cheeky answer would be "just
enough".

Please do bear in mind that my experience is predominantly in C++ so I
guess I still view things from that angle, my experience in Java is
but a few weeks old, mind you fairly intensive reading up on it,
nevertheless still at its infancy.

I am fairly excited about the things that Java has to offer, so once
more thanks to all for your help on this one. It is genuinely
appreciated.

Kind Regards,
Sakis
 
L

Lew

It would be a major understatement to say that I strongly believe in
the Programming to an Interface paradigm. With that in mind, you
mentioned that you can't protect the user from screwing things up in a
rather spectacular manner and I whole heartedly agree with that
statement. But sure as hell I want to make it difficult for them to
screw it up. So the question goes against how much effort you want to
invest to achieve that? I guess a cheeky answer would be "just
enough".

Actually, you can lock down a whole lot, nearly everything. This is
the API writer's perspective. Tricks like judicious use of the
'final' keyword, use of private or package-private implementing
classes, factory methods in lieu of exposed constructors and others
make it possible to regulate the use of your API.

The superb and seminal /Effective Java/ by Joshua Bloch includes items
that address these concerns.
<http://java.sun.com/docs/books/effective/>
 
B

blue indigo

It would be a major understatement to say that I strongly believe in
the Programming to an Interface paradigm.

I think you mean what is more commonly called Design by Contract.
I want to make it difficult for them to screw it up. So the question
goes against how much effort you want to invest to achieve that? I guess
a cheeky answer would be "just enough".

I'd be more concerned with making it easy for them to avoid screwing it
up. If they are determined to screw it up, they will, as you yourself have
noted.

Measures that make it more difficult to screw up, but come at the expense
of flexibility or extensibility, are probably best avoided.

Measures that make it easier to avoid screwing up, on the other hand may
be warranted even so.

Meditate for a while on the difference between those two things. There is
not complete overlap.

(As a hint: Java Generics make it easier to avoid screwing up types in
collections, and also have other uses. Significantly, it is possible to
completely circumvent generics, though rarely is it desirable to do so.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,266
Latest member
DavidaAlla

Latest Threads

Top