Skip to main content
Ebun.1
Senior
May 21, 2021
Solved

I want to pass variables to some views

  • May 21, 2021
  • 3 replies
  • 1099 views

Thank you for helping.

I want to access common variables on several screens (View).

How do I pass a variable to View?

Will it be passed to the base class of View?

I want to make it a smart way without using global variables.

Thank you.

This topic has been closed for replies.
Best answer by MM..1

Smart is global, when you dont like global , then you create MODEL - PRESENTER - VIEW, but in real your variable master exist in MODEL as class variable, then is protected from access it on other threads . And for use in views need create setter and getter methods in every view and presenter...

3 replies

MM..1
MM..1Best answer
Chief III
May 23, 2021

Smart is global, when you dont like global , then you create MODEL - PRESENTER - VIEW, but in real your variable master exist in MODEL as class variable, then is protected from access it on other threads . And for use in views need create setter and getter methods in every view and presenter...

Ebun.1
Ebun.1Author
Senior
May 24, 2021

Hi MM ..1

I am always grateful for your help.

Sometimes the global is smarter, isn't it?

I will think about it.

BParh.1
Senior III
May 24, 2021

In my opinion I would not use global variable here especially for complex application. While it might be convenient, but is poor in term of localization as everything in the code can access those variables. And it doesn't scale well as it would get messier when application is getting complex.

A more sound approach is to leverage existing TouchGFX Engine architecture Model-View-Presenter

https://support.touchgfx.com/docs/development/ui-development/software-architecture/model-view-presenter-design-pattern

All the data intent to persist over the View classes mus be in model class. But in order view to reflects Model data changes, it has to go through the Presenter class.