- How to proceed?
- Splitting existing code
- Extract business logic
- Options related to Business logic / UI code splitting
- Project description
- Window description
- Describing a page
Splitting Business logic / UI code
During the development of an application, the code that is specific to the interface and the code that is specific to the business logic (access to databases, etc) are often "mixed". Who hasn't used the click process on a button to save data in a data file and to refresh a window?
WINDEV, WEBDEV and WINDEV Mobile help you split your code to separate business logic from UI code.
This division has several advantages:
- structure your code,
- make reusing and sharing code easier,
- simplify the webification of your application,
Splitting your code will also allow you to use an MV or MVP development method.
WINDEV, WEBDEV and WINDEV Mobile propose to split the code gradually: you can start by splitting your code on new windows only, then on the whole project, window by window.
You can also perform this operation to structure the code of your application, or to choose and generate the classes (or sets of procedures) necessary for re-using and sharing your code.
WINDEV, WEBDEV and WINDEV Mobile provide you with the tools and you decide how to use them.
Splitting existing code
To split UI code from Business Logic in an existing code, follow these steps:
- Open the project in the desired product.
- Open the code editor (Press F2 on a button, for example).
- Enable Business/UI highlighting: in the code editor, go to the "Refactoring" pane, "Business/UI" group, expand "Display Business logic/UI" and select the desired coloring mode:
- No coloring
- Coloring in line background: in this case, the coloring is applied on the entire line of code.
- Coloring on the border: in this case, the coloring is applied only on the border of the lines of code.
- Coloring applies to all projects.
- The coloring is applied according to the following rules (light theme):
- Lines of code related to UI in a UI process are colored in green.
- Lines of code related to Business logic in a UI process are colored in orange.
- Lines of code related to UI in a Business logic process are colored in orange.
- Lines of code related to Business logic in a Business logic process are colored in blue.
- Enable Business/UI errors: in the code editor, go to the "Refactoring" pane, "Business/UI" group and click "Enable Business/UI errors". This button enables the Business/UI errors for the current element (window, page, etc.) only.
Business/UI errors are displayed in the "Compilation errors" pane, among the programming standard errors ( ).
- Split your code to prevent this type or error.
- If necessary, create local (or global) procedures to split your Business logic from UI code.
- If necessary use the attributes <UI> and <Business>. In a code or process containing both UI code and Business logic, these attributes are used to indicate the use of the variable or procedure.
Example: The procedure DisplayTrip is considered as a procedure that deals with the UI (<UI> attribute) even though it calls RetrieveTrip, a business procedure.
Remark: Calls to business procedures in a UI process are enclosed by a blue border.
Extract business logic
When all code mixing errors are corrected in the project, it is possible to automatically create global classes or procedures that group all local procedures created to separate the UI code from the Business Logic.
This operation is useful and recommended:
- If your project is shared,
- If your project must be webified,
To extract the Business logic:
- In the code editor, on the "Refactoring" pane, in the "Business/UI" group, click "Extract Business logic".
- In the window that is displayed:
- Select the desired type of splitting: Class or set of procedures.
- Specify the name of the class or set of procedures.
- The specified element is automatically created and the code is modified to use the set of procedures or the class.
Options related to Business logic / UI code splitting
The option "Indicate when the Business logic and UI code are mixed" in the project description window ("Compilation" tab) makes it possible to enable or disable the Business/UI errors on all the elements of the project.
Remark: It is recommended to use this option on individual elements before using it on the entire project.
In a window description, the "Details" tab allows you to define the programming standard via "Programming standard".
In the interface for defining the programming standard, you can enable the Business/UI errors for the current window.
Describing a page
In a page description window, the "Details" tab makes it possible to define the programming standard via "Programming standard".
In the interface for defining the programming standard, you can enable the Business/UI errors for the current page.
This page is also available for…