On Sat, Apr 26, 2008 at 04:46:11AM -0700, John Patterson wrote:
> 
> 
> 
> John Krasnay wrote:
> > 
> > This rule is too strict. Another way to avoid calling overridable
> > methods from the constructor is to use a model:
> > 
> 
> Models are fine for providing dynamic values but do not help you customise
> components by extension.  For example, to provide a different type of link
> to use in the component (as PagingNavigation allows)

Sure, but your rule said "Call all overridable methods from
onBeforeRender()", and I gave you a working counterexample that has
nothing to do with onBeforeRender.

The rule should really be "Avoid calling overridable methods from the
constructor." onBeforeRender is a good strategy to use when you need
information from your subclass to *construct* a sub-component (e.g.
"...to provide a different type of link..."), but it's really overkill
if you simply need a value that comes from the subclass, e.g. as a label
value.

Since you've volunteered to write up a wiki page :-) here's another
pattern I use quite a bit: providing overridable methods in the panel to
turn on and off elements within the panel:

BAD:

public class MyPanel extends Panel {
    public MyPanel(String id) {
        super(id);
        add(new Label("name", ...).setVisible(isNameVisible()));
    }
    public boolean isNameVislble() {
        return true;
    }
}


GOOD:

public class MyPanel extends Panel {
    public MyPanel(String id) {
        super(id);
        add(new Label("name", ...) {
            public boolean isVisible() {
                return isNameVisible();
            }
        }
    }
    public boolean isNameVislble() {
        return true;
    }
}

jk

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

Reply via email to