tags:

views:

291

answers:

4

if i have a class gui and a class for the logic, is holding a reference in gui to logic and logic to gui very bad?

A: 

If you can avoid it, you probably should. Otherwise you might get into a lot of problems with circular dependencies later.

Do they really have to know about each other, or could you have a third "control" concept referencing the two?

Nicolai
+9  A: 

As a general rule it is bad to have the "logic" class having knowledge of the "gui" class. The idea behind the separation is the Model/View design pattern (or Model/View/Controller). The view will need a reference to the model. Look really closely at why the model needs a reference to the view. Usually when the model needs to send information to the view event listeners are used (see javax.swing table and list models for an example).

John Meagher
+4  A: 

It should be avoided. In your GUI, you can have a reference to your Domain Logic, but you should not have a reference to your GUI in your domain logic.

Why ? Because otherwise, you have no advantage of splitting GUI & Domain logic up in separate files. When your Logic has a dependency to your GUI, then you cannot use your Logic with another GUI.

So, you should try to avoid this dependency from your logic to your gui, or, you should make abstraction of it.

I hope i'm making myself clear here. :)

Frederik Gheysels
A: 

The GUI probably needs to expose some kind of interface to the logic class, to have the GUI update when the logic class changes something.

The logic should not have direct knowledge of the the GUI implementation, only its interface.

The Observer Pattern is sometimes used for this.

Christoffer Hammarström