Hello Everyone.
I want to ask what are the best practices to access and/or modify data from "native" code. Let me explain with an example :
In my C++ source code I have many methods that look like the following :
void DeviceExamsModelClass::GetAvailableExams()
{
etl::vector<SDKEnums::AudExamType, SDKEnums::ExamTypesNumber> availableExams = m_examsManager->GetAvailableExams();
for (uint8_t i = 0; i < availableExams.size(); i++)
{
// APPROACH 1
DeviceExamsVMUnitDeviceExamsVMClass__UpdateAvailableExams(m_ExamsVM, (XInt32)availableExams.at(i), i); // Use EmWi function to access ViewModel data
// APPROACH 2
m_ExamsVM->AvailableExams[i] = (XInt32)availableExams.at(i); // Directly write data in ViewModel's array
}
}
I am using a Model / View / ViewModel architecture.
In Embebbed Wizard I declare and implement "ViewModel" classes, which contain all the methods and variables needed to exchange data between the Model and the View.
To provide data to the GUI in the Model's source code I usually call a ViewModel function ( "APPROACH 1" in the code snippet).
With this approach I needto write a method for every possible data exchange between model and view, which can result a little pedantic.
I found that I can directly access ViewModel's variables ( "APPROACH 2" in the code snippet). This allows me to make ViewModels slimmer, and I appreciate that most of the data access responsibilities remain in the model.
I would like to know if this approach is safe/advisable, what are its possible disadvantages or problems, and if it is better to continue using the "classic" approach that connects Model and ViewModel with a dedicated method
Thanks in advance and Best regards,
Dario.