I have a class whose constructor looks something like this:
abstract class BasePanel extends JPanel { public BasePanel(A a) {
In the constructor, the fields are first initialized, which should be initialized with the values passed to the constructor. Then, the other methods needed to configure the UI are invoked in order. Two of these methods must be overridden in a subclass to customize their user interface.
Now consider the FooPanel
class, which extends BasePanel
. It requires a few more initialization parameters in its constructor.
class FooPanel extends BasePanel { public FooPanel(A a, B b) { super(a); this.b = b; } @Override public void initializeComponents() { super.initializeComponents();
initializeComponents
requires b
here, which, unfortunately, is not initialized at this point.
What would be a suitable way to restructure this code so that:
- Required fields are set until necessary.
- code that uses
FooPanel
(and other panels) is not heavily overwhelmed by this change.
Any help is greatly appreciated. Thanks.
source share