Re: Good practise?



On Mon, 17 Jul 2006 13:40:15 +0100, Rhino <no.offline.contact.please@xxxxxxxxxx> wrote:

I don't see why it would be a problem to invoke a method that enables or
disables GUI controls from a constructor. I've done so many times and have
no regrets.

Then again, I've never had the particular code examined by an OO design guru
so maybe such an activity violates a design precept of some kind.

To my way of thinking, the constructor's job is to build an instance of an
object. If that object is a GUI, then I don't see why enabling/disabling
controls on that GUI should be avoided within the constructor.


I agree. However, you should be aware of the potential issues around calling overrideable methods from a constructor. If the method is private or final there should be no problem. If not, there could be subtle bugs if the method is over-ridden by a sub-class. This is because the object is not guaranteed to have been initialised before the method is invoked (the superlcass constructor will then be calling a method on the sub-class).

Dan.

--
Daniel Dyer
http://www.dandyer.co.uk
.



Relevant Pages

  • Re: Can someone use invokeLater() to call a public method from a JPanel?
    ... This is for a simple card game.I want to call a public method ... >> in the JPanel and adds a Label representing each of the cards to the ... >> For some reason if I call this method from the constructor of the JPanel ... I suspect it Is working, but that you GUI has not been fully rendered, so you ...
    (comp.lang.java.programmer)
  • Re: form inheritance
    ... some of the other "regular" forms that constructor is good enough, ... constructor of MySpecialClass). ... 1.I don't know of a better thing to inherit from ... you said you didn't want a GUI. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Waiting for user input in a GUI
    ... Michal Brzozowski wrote: ... the constructor to create a window and let the ... The problem is that the constructor creates the ... GUI and exits, and data from the user arrives ...
    (comp.lang.java.help)
  • Re: Good practise?
    ... I will also need to disable selected controls during further processing, ... method from within a constructor? ... disables GUI controls from a constructor. ... If that object is a GUI, then I don't see why enabling/disabling ...
    (comp.lang.java.programmer)
  • Re: Help needed (GUI/passing objects)
    ... > This error occurs whenever I pass in the state object to the GUI ... The error is pointing to the end of the constructor (I assume that was what ... The way that error message is shown with ...
    (comp.lang.java.help)