2

I'm currently developing a Python program with a GUI based on Qt 5. I use a MVC template I found on Github.

Let's assume that a single check box was checked or unchecked and the model was updated. Changing the model causes the view to update itself because the view is an observer of the model. Updates of the view are done by the update_ui_from_model(self) method within the MainView class.

If my aplication window contains a lot of widgets (TextEdit, PushButton, RadioButton, ...) all of them will query its state/content from the model although only one check box changed.

This looks not very efficient for me. Is it possible to reach that (in my example) only the checkbox queries its new state from the model? I hope that I understood the concept in the right way. ;)

1 Answer 1

1

This depends very much on the exact nature of the application. Typically, “the model” is an assortment of data/business logic and not just a single object. Each part of the view would then only observe those parts of the model that are relevant to it. You might also consider that there are different kinds of events in the model, and that the observing view parts are only interested in a specific kind of event/signal. Perhaps you could filter these events and skip unnecessary updates?

Of course this leads to increased complexity. You have to decide: are fewer updates worth the increased complexity? Your current design might be good enough.

There are also a number of alternative architectures to manage this data flow. E.g. MVVM makes a distinction between the general model and the observable ViewModel. In MVP, a Presenter mediates between the view and the model, so that the UI isn't directly registered to model events. These architectures are not inherently superior to MVC, but you don't have to use MVC if you don't feel it is suitable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.