Thanks. That works perfect. I was thinking it should be harder than
that!
-Mike
Hi,
note that such a cast is (in most cases) a hint for a bad design - in
this case a hint that perhaps bsd_mike should not extends Button but
should rather have a method 'getComponent()'. (Note that this is close
to your first solution.)
Ciao,
Ingo
Steve W. Jackson - 01 Dec 2006 17:46 GMT
> Hi,
>
[quoted text clipped - 5 lines]
> Ciao,
> Ingo
Failing to quote relevant portions of a preceding message makes it hard
to grasp what you just said...
I don't freely advocate use of "instanceof" in code, as it often is bad
design. But in the OP's situation, there was not enough information
about whether his interface would always be used in his code within a
specific kind of class (Component subclasses) or not. So the end result
of using the getComponent approach is still not entirely clear...what if
his interfact is to be implemented in something besides a Component
subclass? By virtue of its presence in the interface, he'll be required
to implement the method...but what will he return?
As always, a "correct" reply can only occur with all the facts in hand.
I have no idea whether he provided all the facts or not.
= Steve =

Signature
Steve W. Jackson
Montgomery, Alabama
Dale King - 02 Dec 2006 01:08 GMT
> Hi,
>
> note that such a cast is (in most cases) a hint for a bad design - in
> this case a hint that perhaps bsd_mike should not extends Button but
> should rather have a method 'getComponent()'. (Note that this is close
> to your first solution.)
Which is also an indication the AWT and Swing should have been designed
with some interfaces that specify the behavior of the underlying
implementations. In reality Component should have probably been an
interface and what is currently Component should be something like
AbstractComponent. Sun was unfortunately very inconsistent on how well
it applied OO design principles.

Signature
Dale King