ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / Developing an application or website / MVP (Model, View, Presenter)
  • Overview
  • WLanguage: Specific features to simplify MVP architecture
  • Overview
  • "Mapping" attribute
  • MyMappedFile and MyUniqueMappedKey keywords
  • "Associated" attribute
  • Attribute "presentation": management of view refreshing
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Overview
WINDEV proposes an MVP RAD that generates the "table" and "form" windows as well as the necessary Presenter and Model classes.
The windows correspond to the Views of MVP.
The generated code is freely and fully adaptable to your needs: it's the generation of a basic application skeleton.
Caution: This development mode uses OOP: it's mandatory to master its concepts.. This development mode is an advanced development mode.
AndroidiPhone/iPadMac Catalyst The MVP RAD is not available. An example with the different classes to build an MVP application is available.

Related Examples:
WM Discover MVP Cross-platform examples (WINDEV Mobile): WM Discover MVP
[ + ] This example shows the implementation of an MVP (Model View Presenter) architecture in a project. This example has been simplified to better explain the concepts of this architecture.
WLanguage: Specific features to simplify MVP architecture

Overview

To simplify the implementation of an MVP architecture, it is important to identify and understand the specific WLanguage elements:
  • the mapping attribute (as well as the MyMappedFile and MyUniqueMappedKey keywords),
  • the associated attribute,
  • the "Presenter" attribute,
  • the RequestRefreshUI and RequestRefreshUIParent functions, and the window (or report) refresh event.
The MVP RAD uses these features but they can be used in any type of architecture.

"Mapping" attribute

The mapping attribute is used to create a "direct link" between the class and the data file.
Example:
MMyExampleFile is Class,mapping = MyExampleFile
Via this attribute:
  • MemoryToFile will automatically copy the value of class members into the items of current file record.
  • FileToMemory will automatically copy the items of current file record into the class members.
Important:
  • In order for this mechanism to operate, the names of class members must be identical to the names of items in the data file.
  • If required: the mapping attribute allows you to use prefixes or names other than those used in the analysis.. To do so, re-use the mapping keyword on the members of the class to recreate the link between the member and its analysis item.
    Example:
    m_sEstateTitle is ANSI string <MAPPING=EstateTitle>

MyMappedFile and MyUniqueMappedKey keywords

In the MBase class generated by the MVP RAD, two keywords are used to simplify mapping management: MyMappedFile and MyMappedUniqueKey.. These keywords are used to identify, for the MBase base class, the file and the unique key of model:
  • MyMappedFile references the data file defined by the mapping keyword in the "Model" class.
    For example, the following code is used in the bSave method of the MBase class:
    HReset(MyMappedFile)

    This code will perform a call to HReset on the data file for which the RAD was generated.
  • MyUniqueMappedKey references the item defined by the "unique key" mapping in the "Model" class.
    For example, in the MMyExampleFile class, MyUniqueMappedKey is equivalent to the MyExampleFileID item:
    m_nMyExampleFileID is int<MAPPING=MyExampleFileID, unique key>
These keywords allow you to use generic code in this base class.

"Associated" attribute

The associated attribute is used to access the members, the methods and the properties of a Model class from its Presenter class without having to perform any "rebounds".
Example:
PFormMyExampleFile is Class
PROTECTED
m_clCurrentModel is MMyExampleFile <associated>
In the above example, the PFormMyExampleFile objects have an "associated" member whose type is MMyExampleFile.
The PFormMyExampleFile objects directly expose the methods, properties and members of the associated class, without having to redefine them.
Via the associated attribute, there is no need to systematically recreate all the properties in the presenter class to expose the members of the model.
The MVP architecture generated by RAD contains generic classes and classes specific to the project. It can be entirely customized!
Simply create the desired methods and properties in the "Presenter" class to override the behavior of the model.
You have the ability to link a control to a member or to a property of the "Presenter" class. Therefore, this link can be performed on all the member or properties of the "Model", exposed by the "Presenter" class with this mechanism.

Attribute "presentation": management of view refreshing

The presenter attribute is used during the global declaration of the generated windows. It is used to associate a class of the presenter layer with a view (window or report).
For example:
PROCEDURE WIN_Table_MyExampleFile(...
	gclPresenter is PTableMyExampleFile dynamic<presenter>=Null)
When this attribute is used, the call to the window refresh event will be triggered by:
For example, when deleting an element from a Table window generated by the MVP RAD, a request for updating the UI is performed by the call to RequestRefreshUI:
  • MArrayMyExampleFile is associated member of PTableMyExampleFile,
  • PTableMyExampleFile is defined as "presenter" of the "WIN_Table_MyExampleFile" window.
Then, the refresh event of "WIN_Table_MyExampleFile" will be automatically called when an element is deleted.
The UI refresh event allows grouping all the window refresh processes together, rather than distributing them into several events (click, etc.).
This mechanism is also found in the form window. The form window is linked to the presenter class PFormMyExampleFile containing an associated member MMyExampleFile. Therefore, the refresh requests performed in MMyExampleFile affect the form window.
Caution: The UI update event must not be executed "anywhere"..
Important The RequestRefreshUI and RequestRefreshUIParent functions are asynchronous: the UI update event is executed at the end of the current process, and calls to the RequestRefreshUI or RequestRefreshUIParent function are not stacked. These functions and this mechanism can even be used outside an MVP architecture. This offers a major advantage: if a processing loop in the model makes 50 calls to function RequestRefreshUI, WLanguage will only make a single call at the end of processing (so the UI doesn't "blink")..
Note: to make a synchronous UI update request, simply use the WLanguage function ExecuteRefreshUI (or ExecuteRefreshUIParent).
Minimum version required
  • Version 20
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 11/15/2024

Send a report | Local help