Design Question
From: Robert Mark Bram (none)
Date: 07/11/04
- Next message: Chris Smith: "Re: Java Swing: JFrame Window Maximisation"
- Previous message: George Neuner: "Re: problem with 'double'"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 11 Jul 2004 15:17:13 +1000
Hi All!
I begin a GUI class. I have a Control class. Both have exit methods - but it
is the Control class' exit() method that
always gets called in the end:
public class Control{
protected exit() {
System.exit(0);
} // end exit
} // end Control
// Has a frame.. builds and displays it
class Gui implements ActionListener{
private Control control;
public Gui(Control control){
this.control = control;
} // end constructor
public void actionPerformed(ActionEvent event){
// if exit..
control.exit();
} // end actionPerformed
} // end Gui
Here is my problem. I have a nested MenuBar class in Gui that handles its
own actions, and it is getting large, so I
split into its own class:
public class Control{
protected exit() {
System.exit(0);
} // end exit
} // end Control
// Has a frame.. builds and displays it -
// and adds GuiMenuBar as its JMenuBar
class Gui implements ActionListener{
private Control control;
private JMenuBar guiMenuBar;
public Gui(Control control){
this.control = control;
this.guiMenuBar = new GuiMenuBar(this);
} // end constructor
public void actionPerformed(ActionEvent event){
// if exit..
control.exit();
} // end actionPerformed
protected exit() {
control.exit();
} // end exit
} // end Gui
class GuiMenuBar extends JMenuBar implements ActionListener{
private Gui gui;
public GuiMenuBar (Gui gui){
this.gui = gui;
} // end constructor
public void actionPerformed(ActionEvent event){
// if exit..
gui.exit();
} // end actionPerformed
} // end GuiMenuBar
So this is my problem...
The app can be considered a composition of Control and Gui.
Gui is composed of itself and GuiMenuBar..
But to provide functionality along the chain I am putting in protected
methods in the middle.
Is this a good thing or a bad thing?
Is there a different design pattern to use?
I have been looking at the Model-View-Controller pattern, but it doesn't
solve this - the essential problem being
that I am splitting the View portion into separate classes..
Any advice would be most appreciated!
Rob
:)
- Next message: Chris Smith: "Re: Java Swing: JFrame Window Maximisation"
- Previous message: George Neuner: "Re: problem with 'double'"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|