Where should the main event loop be located? Model, View, Controller? Or maybe, generally from the outside, in the maine? Or in another class that MVC encapsulates?

How correct?

upd: Answering the comment, why is it needed in MVC: I need it for the reason that I personally do not understand how to organize logic in MVC and applications with GUI in general. In my understanding, somewhere in the code there must be something in the spirit

while(true) { while(app.EventHappened()) { if (app.LastEvent() == App::Event::Click()) { doSomeLogic(); } } app.display(); } 

In any case, I suppose that this can be done at least in MVC. The question is where to shove it so that it is correct from the point of view of architecture.

  • And why, excuse me, does MVS necessarily require a main event processing loop? Why, for example, do not have each model component? On the other hand, why is it even needed? MVC does not prescribe it. - VladD
  • Added to the question why I need it in MVC. - NikBond

1 answer 1

It depends on many factors, there is no prescribed standard.

For example, if you have a MVC pattern that implements a Web application, then the UI (and its internal loops) runs in the browser of the user, and requests from the browser may well work out on the server thread pool.

If you have an ordinary desktop application, then yes, the classic frameworks require a single "main" loop, in which the UI and most of the controller run. Model components may well have their own message cycles.

Since the MVC pattern does not require a message loop, it does not impose any requirements for finding it. In this case, usually the main loop starts the component that starts first (View or controller). But in my opinion, the cleaner code will consider the main cycle startup code as a separate part of the application, which is not, in the strict sense, part V or C. In any case, do as you wish.