views:

146

answers:

2

I have a set of nonGUI objects which have a one to one realtionship with GUI objects. All events are routed through the top level window.

Many ( not all ) events occuring on the GUI object result in calling a method on the associated object.

Some methods in the NonGui objects which when called change the GUI objects.

One example would be some sort of game like Rogue with a modern GUI. You have the area a player occupies in one turn ( call it a region ) and you have the object ( a button ) associated with it on the GUI. Keep in mind it's only an analogy ( and not even the real problem ) and no analogy is perfect.

The question is, how does one design this sort of thing?

Since the button class is from a third party library, I cannot imbed a reference to the nonGUI object in it, though I can imbed a reference to the GUI object in the nonGUI object. So it looks likeI will have to create a map from a buttons to "regions" somewhere, but where do I put it? In the toplevel window? In the top level model? Do IU spin off some sort of interface class?

Suggestions?

+3  A: 

It would help if you mentioned your platform and language, but generally it sounds like you are describing Model-View-Controller.

Your "GUI" object(s) are the View. This is where you keep all the rendering logic for your user interface. User interactions with the View are handled by the Controller.

The Controller is a thin layer of event handles. User interaction calls methods on the Controller, which then routes them to the Model.

Your "non-GUI" object(s) are the Model. This is the object that contains business logic and whose state is ultimately updated by clicking buttons on your GUI.

You mention "embedding" references between the objects. This is not necessary as long as events in your GUI can be routed by some mechanism to your Controller. This design pattern is useful because it separates your UI logic from your business logic. You can "snap on" a new Views very easily because there is very little event wiring between the View and the controller.

The Wikipedia article has more information and links to implementation examples.

Dave Swersky
A: 

Waste a little time looking at Falcon's Eye (though it is Nethack rather than Rogue). There's a long history of skinning rogue like games (or command line apps in general), which isn't quite classic mvc - it already has a full UI, instead you're adding a decorator to that UI with either a direct translation, or another metaphor (such as gparted, the gnome partition editor, which allows construction of a sequence of partition editing commands by direct manipulation)

Pete Kirkham