2 classes refer to each other, is this normal?

if I have a gui class and a class for logic, contains a link in gui to logic and logic for gui is very bad?

+6
java class
source share
4 answers

As a rule, it is bad to have a "logic" class that owns the "gui" class. The idea of ​​separation is a model / view template (or Model / View / Controller). The view will require a reference to the model. Take a close look at why the model needs a reference to the view. Usually, when models need to send information to a view, listeners are used (see the javax.swing table and list models for an example).

+11
source share

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

Why? Because otherwise, you have no advantage to separate the GUI and domain logic in separate files. When your logic is dependent on your GUI, you cannot use your logic with another GUI.

So, you should try to avoid this dependency on your logic before your gui, or you should do an abstraction.

Hope I explain here. :)

+5
source share

If you can avoid this, you should probably do it. Otherwise, you may encounter many circular dependency problems later.

Do they really need to know about each other, or do you have a third concept of "control" that refers to two?

0
source share

The GUI should probably expose some kind of interface for the logical class in order to update the GUI when the logic class changes something.

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

For this, the Observer Pattern is sometimes used.

0
source share

All Articles