mardi 15 novembre 2022

Python - reference class each other (information flow)

I would like to know, what is the concept of information flow in GUI based apps, or any other app with same problem. When you have two seperate classes and their objects, how is the messeging process done between them. For example you have a GUI and AppLogic.

Scenario 1: Button is pressed -> GUI is processing event -> calls AppLogic method image_clicked()

Scenario 2: HTTPServer gets a message -> AppLogic receives image -> AppLogic calls GUI method render_image()

enter image description here

The problem is that you cannot reference classes each other because the first class does not know the second one (here AppLogic does not know GUI class):

class AppLogic():
    gui : GUI

    def image_clicked(self):
        pass #not important
    
class GUI():
    app_logic : AppLogic
    
    def render_image(self):
        pass #not important

I know this is more like go to school and study problem, but I would like to know how these problems are sovled, or some common practices. At least link with some detailed information. I am not able to name the problem right to find the answer.

Aucun commentaire:

Enregistrer un commentaire