Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #34429

Re: How to extend an array

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: How to extend an array
Date 2016-05-31 14:11 -0400
Organization A noiseless patient Spider
Message-ID <nikk4d$ao3$1@dont-email.me> (permalink)
References <ae727260-8c33-4648-8995-f387a6eb8b52@googlegroups.com> <nikc0f$b0v$1@dont-email.me> <f46278e9-a64d-42d4-8c2d-5e0cfd168692@googlegroups.com>

Show all headers | View raw


On 5/31/2016 12:09 PM, Eric Douglas wrote:
> On Tuesday, May 31, 2016 at 11:53:00 AM UTC-4, Eric Sosman wrote:
>>      I don't see why Class2 needs its own list of listeners, nor its
>> addExtendedListener() method.  Since Listener2 extends Listener1, a
>> Listener2 "is a" Listener1 and can be handled just fine by Class1's
>> addListener() method.  Unless there's some additional concern that
>> you've simplified away, I think you're working too hard.
>>
>>      Side-issue: Since Class1 and Class2 extend JFrame, they are both
>> Swing components.  Swing components are not thread-safe (by and large),
>> so it's not safe to manipulate them from more than one thread.  That
>> thread should be the Event Dispatch Thread or EDT.  Your code, though,
>> does a *lot* of manipulation of these Swing components on a non-EDT
>> thread: It constructs them, resizes their windows, and makes them
>> visible, all from the startup thread that calls main().  Don't Do That.
>> (To be fair to you, Sun themselves didn't at first realize this was a
>> no-no, and some of the early Swing examples commit this same error.
>> Pay attention to more up-to-date examples, that's all I can suggest.)
>
> As I mentioned this is a simple sample to show the structure, so yes those are non issues.  You see Listener2 has additional methods.  Class2 in the sample didn't call the method(s) but will need to.  Test programs instantiating a Class1 will need to handle all Listener1 methods.  Test programs instantiating a Class2 will need to handle all Listener1 methods plus the additional methods in Listener2.  The second issue, yes, Eclipse runs this sample as is and I left it out but I do normally instantiate the Swing GUI objects (JFrame, or JDialog) from an EventQueue.invokeLater().

     It doesn't matter that Listener2 has additional methods beyond those
of its base interface Listener1: Any class that implements Listener2
perforce implements Listener1, so a Listener2 implementation "is a"
Listener1 implementation, and can be handed to Class1's addListener().
In fact, in your sketch you do exactly this: Class2 hands the Listener2
it is given to its Class1 superclass, which accepts it because ... it
"is a" Listener1.

     As for users of Class2 being required to handle the additional
methods of Listener2 -- well, I'm afraid I don't see the need.  Since
a Class2 "is a" Class1, a user of Class2 instances should be able to
treat them as Class1 instances (because they "are"), and should thus
be able to deal with Listener1 events alone.  If for some reason this
is not possible, I think there's something highly suspect about your
design: It's like "MyList extends AbstractList, but you can't treat it
like a List."  Perhaps a less "simplified" example would help ...

> The question here is about the array.  Does this make sense, having a class extending a class overriding a method that accepts an object for an array with a class which extends that object's class, just using an array of the same name and having to add it to that array plus the super...?

     Since I'm still not sure I understand what you're trying to do,
I can't comment.  Not usefully, anyhow.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-05-31 07:52 -0700
  Re: How to extend an array Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-05-31 11:52 -0400
    Re: How to extend an array Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-05-31 11:56 -0400
      Re: How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-05-31 09:19 -0700
        Re: How to extend an array Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-05-31 14:01 -0400
    Re: How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-05-31 09:09 -0700
      Re: How to extend an array Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-05-31 14:11 -0400
        Re: How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-05-31 11:25 -0700
          Re: How to extend an array Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-05-31 17:01 -0400
            Re: How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-06-01 04:57 -0700
  Re: How to extend an array Roedy Green <inquiry@mindprod.com> - 2016-05-31 21:56 -0700
    Re: How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-06-01 04:49 -0700
  Re: How to extend an array Robert Klemme <shortcutter@googlemail.com> - 2016-06-01 23:07 +0200
    Re: How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-06-03 05:38 -0700
      Re: How to extend an array Robert Klemme <shortcutter@googlemail.com> - 2016-06-04 19:17 +0200
    Re: How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-06-03 08:52 -0700

csiph-web