On Mon, Apr 28, 2008 at 10:48 PM, Martijn Dashorst
<[EMAIL PROTECTED]> wrote:
> On 4/28/08, James Carman <[EMAIL PROTECTED]> wrote:
>  > So, how do you know that everything is good to go in the subclass
>  >  then?  You really shouldn't be calling a method implemented by the
>  >  subclass in the superclass' constructor.  In your case, it may work,
>  >  but in general, it's bad practice.
>
>  In general programming with your brain shut down is bad practice. I
>  see a lot of fear, uncertainty and doubt about calling overridable
>  methods from a constructor. There is no need to if you engage your
>  brain.
>
>  The biggest problem is that components may not have their final
>  position in the page yet, so you can't call some methods. Guess what?
>  That isn't any different from calling those methods in the constructor
>  in the first place. And it is easily solved by moving that logic to a
>  delayed execution such as a Model's getObject() method. Which really
>  provides a better solution in the first place.
>
>  Martijn
>

Hi,

Could you give a small example of such solution (like: "moving that
logic to a delayed execution such as a Model's getObject() method")?
Scott's use case would be a good starting point (pasted below). I
still don't know how to specify the component to pass to the add
method in the BasePage constructor. How would you change this to avoid
these "createXXXPanel()" calls (I hope you are not thinking about
calling add(...) methods in the RedPage constructor of course :))?

public BasePage(...) {
 add(createFooPanel("fooId"));
 add(createBarPanel("barId"));
}

protected abstract Panel createFooPanel(String id);
protected abstract Panel createFooPanel(String id);

-----

public RedPage(...) extends BasePage {
 super(...);
}

@Override
protected Panel createFooPanel(String id) {
 // do not reference anything that is instantiation dependent
 return new RedFooPanel(id);
}

@Override
protected Panel createBarPanel(String id) {
 // do not reference anything that is instantiation dependent
 return new RedBarPanel(id);
}

--
Daniel

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

Reply via email to