Skip to main content
Tuoman
Senior II
February 5, 2021
Question

Why not bypass Presenter when fetching data from Model?

  • February 5, 2021
  • 1 reply
  • 559 views

Hi,

I though that I can save a lot of work by bypassing Presenter when fetching data from the Model, like this:

class FrontendApplication : public FrontendApplicationBase
{
public:
 FrontendApplication(Model &m, FrontendHeap &heap);
 virtual ~FrontendApplication() {}
 
 //added this
 Model& getModel()
 {
 return model;
 }
...

Is there any problem with this approach, when fetching/setting Model data?

View <-> Presenter <-> Model

vs.

View <-> Model

If I use Presenter, I need to implement viewPresenter.cpp and viewPresenter.hpp for every single variable, which seems crazy amount of work, for seemingly 0 purpose.

I could just use application().getModel().getVariable(), right?

Thanks!

This topic has been closed for replies.

1 reply

Romain DIELEMAN
ST Employee
February 9, 2021

Hi,

TouchGFX follows the Model-View-Presenter design pattern (MVP) which is a "standard" pattern used for building User Interface applications. You are not wrong in bypassing the Presenter, I personally also avoid working with the presenter when i do quick tests/demo but I usually don't recommend it to prevent bad habits :grinning_face_with_sweat:.

The idea is to divide the code into parts with their own responsibility, the Presenter being in charge of the logic and the View of the visuals.

/Romain