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


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

Re: @java.lang.DontOverride

From Sarah Connor <s.connor@gmail.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: @java.lang.DontOverride
Date 2014-05-14 17:12 +0000
Organization Aioe.org NNTP Server
Message-ID <ll086i$l8k$1@speranza.aioe.org> (permalink)
References <override-20140511031054@ram.dialup.fu-berlin.de> <lkmkeg$qko$1@dont-email.me> <1K5cv.7545$s87.2913@fx11.iad>

Show all headers | View raw


On Mon, 12 May 2014 08:25:58 -0700, Daniel Pitts wrote:

> Stefan, I think the real answer is "Don't add non-private methods to
> your JComponent extension."  Instead, create a different class that
> provides a JComponent object (perhaps a getComponent() method). All of
> the "business" logic that affects the component will live in your
> non-component class, or in the appropriate standard methods of your
> component class.

IOW, "prefer composition to inheritance".

Further to that, you might want to use a private inner class that extends 
JComponent and has direct access to the enclosing object. You'd have a 
factory method in the outer class that returns either a new instance or 
*the* instance (perhaps lazily created), depending on whether you want to 
limit to one instance.

Alternatively ... if your non-component logic has to do with some program 
state that the component displays and/or allows the user to manipulate, 
then you should probably separate it out into a model object and make the 
JComponent subclass a view object, similar to the existing ListModel and 
various list controls (JList, JComboBox, ...).

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


Thread

Re: @java.lang.DontOverride markspace <markspace@nospam.nospam> - 2014-05-10 18:40 -0700
  Re: @java.lang.DontOverride Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2014-05-12 08:25 -0700
    Re: @java.lang.DontOverride markspace <markspace@nospam.nospam> - 2014-05-12 10:11 -0700
    Re: @java.lang.DontOverride Sarah Connor <s.connor@gmail.invalid> - 2014-05-14 17:12 +0000
      Re: @java.lang.DontOverride markspace <markspace@nospam.nospam> - 2014-05-14 10:18 -0700

csiph-web