John Krasnay wrote:

You've just illustrated one of the major problems with the
panel-from-a-subclass approach: it's easy to get it wrong. In your
example, addAbstract1 and addAbstract2 will be called in a class whose
constructor has not yet been called. Consider:

public DerivedPage extends BasePage {

    private String name;

    public DerivedPage(String name) {
        super();
        this.name = name;
    }

    public abstract addAbstract1(String abstractId1) {
        add(new NamePanel(abstractId1, name));
    }
}

This code is broken, since you're constructing NamePanel before name has
been initialized. Someone later in this thread shows a better way to do
this, by calling the overridable methods from onBeforeRender. But this
is also tricky; because onBeforeRender can be called multiple times you
must maintain a flag to ensure you only add your panels once.

In fact, almost all official sources consider this an antipattern (e.g. Effective Java #15), and specifically state that you should never call overridable methods from a constructor at all. So either the method called from the constructor should be private or it should be final.

I wonder what the "official" Wicket policy is on this? Careful documentation?

Regards,
Sebastiaan

Given these subtle problems with this approach, I admit I'm warming to
the multiple extend/child idea.

jk

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

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to