On Mon, 2002-11-11 at 18:15, Jeremias Maerki wrote:
> Hi Peter
> 
> Sorry, that question slipped away under my fingers. But thanks, Kevin,
> for this excellent answer. I couldn't have done it better. So if I may
> provide a short answer to your question and to sum up the mail by Kevin:
> IMO the cost, if any, is by far not enough to outweigh the benefits
> (code readability, clear design, maintenance costs etc) of using the
> interface instead of the implementation. And I agree that instanceof is
> to be used with caution.

In fact it's better than that. Interfaces have NO cost. The only cost is
if you need to cast from the interface to the concrete class (which you
should not need to do).

Casting has a cost, it's small (and very vm dependent) the same for 
instanceof and usually not worth the the effort to avoid.

instanceof may indicate design problems (not always, but often).

-k. 

> On Mon, 11 Nov 2002 09:18:44 +1000 Peter B. West wrote:
> > Jeremias,
> > 
> > This was a serious question, really.  Joerg, when he gets back, might 
> > like to comment on this, because it was as a result of some of his input 
> > that I first realised there was a significant cost associated with such 
> > Java fundamentals as instanceof and type casting.  Those discussions 
> > gave me much food for thought.  So I'll rephrase the question: what, if 
> > anything, is the cost of using the interface instead of the implementation?
> > 
> > Peter
> > 
> > Peter B. West wrote:
> >  > Jeremias,
> >  >
> >  > I have no objection at all, as long as it costs nothing.  It is free,
> >  > isn't it?
> >  >
> >  > Jeremias Maerki wrote:
> >  >
> >  >> Fellow FOP developers,
> >  >>
> >  >> would you mind using the interface instead of the implementation where
> >  >> possible? Map instead of HashMap, List instead of ArrayList. I've seen
> >  >> this habit in a number of places and not only by Keiron! I've made it a
> >  >> habit to follow this pattern
> 
> 
> Jeremias Maerki
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, email: [EMAIL PROTECTED]
> 
-- 
If you don't test then your code is only a collection of bugs which 
apparently behave like a working program. 

Website: http://www.rocketred.com.au/blogs/kevin/


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to