I am preparing for exam in object oriented modelling and design and can't figure out this problem.
The design is in violation of open-closed principle; you can't add more JButtons without modifying the class. Redo the design so that this becomes possible. The design should contain the three buttons and the event management. Avoid duplicated code. Present the new design with a class diagram.
//other code
private Application application;
private JButton b1, b2, b3;
class ActionHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == b1) {
application.action1();
} else if (e.getSource() == b2) {
application.action2();
} else {
application.action3();
}
}
}