I have a "standard" JPanel
with two panels inside. I was trying to create a kind of template class and then extend it and implement the content. The question is about which would be the way to implement it.
The code below is what I'm trying to make it work but I've just started to read the Effective Java book and I'm not familiar with static factory method. Specially trying to abstract them.
Some tips from the book that i'm trying to follow specially are
- Consider static factory methods instead of constructors
- Favor composition over inheritance
- Prefer interfaces to abstract classes
but I couldn't find out a good solution respecting these points (and without them :P).
public abstract class CentralPage {
static JPanel getInstance() {
JPanel container = new JPanel();
container.setBackground(Color.white);
container.setBorder(
BorderFactory.createCompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder(10, 10, 10, 10)));
container.setMinimumSize(new Dimension(960, 400));
container.setPreferredSize(new Dimension(960, 400));
container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
JPanel up = getUp(container);
container.add(up);
JPanel down = getDown(container);
container.add(down);
return container;
}
abstract JPanel getDown(JPanel container);
abstract JPanel getUp(JPanel container);
}
Feel free to ask if you need more information about other parts of code.