Everyone,
Let's say I want to make a base page, extending WebPage. I want to make
it flexible so that subpages may initialize either using a model or page
parameters. So I try to do this:
protected BasePage()
this(null, null);
protected BasePage(final IModel<?> model)
this(null, model);
protected BasePage(final PageParameters parameters)
this(parameters, null);
private BasePage(final PageParameters parameters, IModel<?> model)
super(null, model);
//initialize stuff here
Obviously I can't do this, because several of the WebPage (and ancestor)
constructors are marked private. I'm forced to do this:
protected BasePage()
super();
//initialize stuff here
protected BasePage(final IModel<?> model)
super(model);
//initialize stuff here
protected BasePage(final PageParameters parameters)
super(parameters);
//initialize stuff here
private BasePage(final PageParameters parameters, IModel<?> model)
super(parameters, model);
//initialize stuff here
Look at all the duplicated initialization code! Sure, I could create a
local initialize() method that each of the methods delegate to, but not
only is that ugly it prevents me from making my class variables final
(because final variable must be initialized in the constructor).
Couldn't the parent classes be a little more lenient, allowing access to
all the constructors, making child classes meant to be base pages more
elegant?
Garret
Let's say I want to make a base page, extending WebPage. I want to make
it flexible so that subpages may initialize either using a model or page
parameters. So I try to do this:
protected BasePage()
this(null, null);
protected BasePage(final IModel<?> model)
this(null, model);
protected BasePage(final PageParameters parameters)
this(parameters, null);
private BasePage(final PageParameters parameters, IModel<?> model)
super(null, model);
//initialize stuff here
Obviously I can't do this, because several of the WebPage (and ancestor)
constructors are marked private. I'm forced to do this:
protected BasePage()
super();
//initialize stuff here
protected BasePage(final IModel<?> model)
super(model);
//initialize stuff here
protected BasePage(final PageParameters parameters)
super(parameters);
//initialize stuff here
private BasePage(final PageParameters parameters, IModel<?> model)
super(parameters, model);
//initialize stuff here
Look at all the duplicated initialization code! Sure, I could create a
local initialize() method that each of the methods delegate to, but not
only is that ugly it prevents me from making my class variables final
(because final variable must be initialized in the constructor).
Couldn't the parent classes be a little more lenient, allowing access to
all the constructors, making child classes meant to be base pages more
elegant?
Garret