Design Question

From: Robert Mark Bram (none)
Date: 07/11/04


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
:)



Relevant Pages

  • Re: Multithreaded GUI issues
    ... callback thread that I have no control over. ... In each of these cases, where the events get passed on to GUI components, ... You must use Invoke() or BeginInvokeon any code that will ... It depends on what you do with the Image objects and any resulting data ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: File browser
    ... but to do that you need to be in control of the competing threads. ... The outdated guidance that you could initialize the GUI on the main thread, ... of that control to ensure a synchronization error. ...
    (comp.lang.java.programmer)
  • Re: NTFS Effective Permissions?
    ... > values in previous posts that gave the specific ACE flag values in question ... No, I'm not ignoring it - I've got the print-out in front of me, but I ... this usually DOES show up in the GUI - if you check the ... are showing as "Generic full control". ...
    (microsoft.public.scripting.wsh)
  • gui options galore...
    ... if you want to show a gui then you ... even RapidQ) and compile it. ... then you can send a message to a textbox (edit control) ... to send along binary files with your script. ...
    (microsoft.public.scripting.wsh)
  • Design Question
    ... I begin a GUI class. ... I have a Control class. ... Both have exit methods - but it ... class Gui implements ActionListener{ ...
    (comp.lang.java.programmer)