Reusable Models: Modules & Module Definitions

Manage Large Projects
670 views Published on Mar 21, 2014 | Time 20 min
Applies to: 7.2 or higher

This lesson gives you the basic knowledge required to define reusable portions of IFML models using the module and module definition concepts. Working on real-world Web applications may require modeling a large project. In this situation it’s important to be able to manage the project to avoid loss of control and duplication of model parts. WebRatio Platform lets you easily work on large projects thanks to its modeling capabilities, which allow you to break down a model into parts, and reuse them wherever you need. The main advantages of this approach are ease of maintenance as well as readability and elegance of the obtained model. In fact you can "centralize" the part of user interaction model that you want to reuse and put it in a single place, and that will be the only place where you will have to make changes, thus saving time and reducing errors. Also you can better navigate the IFML model. When you deal with big projects, you often have a complex model with many "View Components" and Pages, so finding something may become difficult.

Transcript

Table of contents

Introduction

Working on real world Web applications may require modeling a large project. In this situation it’s important to be able to manage the project to avoid loss of control and duplication of model parts. WebRatio Platform lets you easily work on large projects thanks to its modeling capabilities, which allow you to break down a model into parts and reuse them wherever you need. The main advantages to this method are ease of maintenance and the elegance of the obtained model. In fact you can "centralize" the part of user interaction model that you want to reuse and put it in a single place - afterwards, that is the only place where you will have to make changes, thus saving time and reducing errors. Also you can better navigate the IFML model. When you deal with big projects, you often have a complex model with many view components and pages, so finding something may become difficult without the capabilities you gain by using WebRatio Platform. This lesson gives you the basic knowledge you need in order to be able to define reusable portions of IFML Models.

Module VS. Module Definition

IFML already includes a concept for model reusability, which is the "Module" concept. A "Module" references a "Module Definition", which is a piece of an IFML Model containing the specification of the content of the module itself.

Module Definitions Types

In WebRatio Platform you can create two different "Module Definition" types, depending on the content you want to add to them:

  • "Content Module Definition"
  • "Hybrid Module Definition"

There are two different types of "Module Definitions" because one can be used as a portion of the content of a page, and the other can be very useful when you want to model a feature, for example the choice of a common object in your application, to use in different places.

Let’s see an example for each of the two Model Definitions.

Content Module Definition

A "Content Module Definition" is a Module Definition that contains a collection of View Components that can be used as a portion of the content of a page.

Content Module Definition Example

An example of "Content Module Definition" in a "CRM" web application is the set of View Components needed in order to show the "Current User Information". This information is usually shown in every page of the Web application. Without the concept of "Module" you would be forced to model the same set of View Components in each page of your Web Project.

How to Add a Module Definitions View

Let’s see how to change the previous model in order to use a "Module" referencing a "Content Module Definition". For this example we continue working on our "CRM" web project in which you have the Domain Model containing the "User" entity, the "Sales Manager" and "Administrator" site views and some pages such as the "Company Details" and the "Search Companies by keyword".

All "Module Definitions" to be used inside the project must be modeled inside a particular view. This particular view is the "Module Definitions View", which is a container of Action Definitions and reusable portions of an interaction flow model.

To add a new "Container View" for "Module Definitions" to your project, open the "Project" tab in the main work area, right-click on the "Module Definitions" icon, and choose the "Add Module Definitions" option from the "Project View". Give a meaningful name to the View, such as "Module Definitions CRM". Press "Finish" to confirm.

How to Refactor into Content Module Definition

You can create a "Content Module Definition" starting from an existing model. Let’s select the View Components we want to add to the "Content Module Definition" from the "Search Companies by keyword" page, in the "Administration" site view. You can click on each View Component while keeping the "CTRL" key pressed (on a PC) or the command key (on a Mac). Then, right-click on the elements and select the "Refactor" and then the "Transform into Module.." option. In the opening dialog, select the "Module Definitions View" in which you want to create the "Content Module Definition". Then press the "Next" button. The next step requires you to provide a meaningful name for the "Content Module Definition", such as "Current User Information". Then press the "Finish" button to confirm the operation.

The result of this operation is that, in the Site View, the View Components we chose before are substituted with a "Module" element, which references the "Content Module Definition" automatically created by WebRatio Platform. To see the "Content Module Definition" model, select the "Current User Information" module, move to the Properties View and press the "Jump to Module Definition" button next to the "Module Definition" property. This takes us inside the referenced "Content Module Definition".

How to Reuse a Content Module Definition

Now that we have the "Module Definition", it’s possible to substitute the View Components contained in each page with the module. Let’s go into the "Company Details" page, in the "Sales Manager" site view. You can select the View Components used before to create the "Module Definition" and delete them. Select the "Current User" get component and the "User Details" details component by pressing the "CTRL" key, as you right-click on them and choose the "Delete" option. Now you can add a Module that references the "Current User Information" content module definition.

Select the "Module" icon from the "Container" section of the left toolbar. Click inside the page. In this case the module is directly associated to the "Current User Information" content module definition, because there is only one "Content Module Definition" in the "Module Definition View". But if there is more than one "Content Module Definition" in the "Module Definition View", we must associate the instance of the module to the correct "Content Module Definition". Then select the "Module" in the page, move to the Properties View and press the "Select" button next to the "Module Definition" property and, in the opening dialog, select the "Module Definition" you want to reference. Press the "OK" button to confirm.

How to Add a Content Module Definitin

It is also possible to model a "Module Definition" starting from scratch, not only from an existing model.

Let’s see how to model a "Content Module Definition". In our "CRM" web project, go to a "Module Definitions CRM" view created previously. Select the "Content Module Definition" from the toolbar and click in the work area. Go to the Properties View and give a name to the "Content Module Definition". In the work area, double-click on the "Content Module Definition" to open the definition. Now you create the model.

Hybrid Module Definition

A "Hybrid Module Definition" is a Module Definition that contains a collection of pages and actions.

Hybrid Module Definition Example

An example of a "Hybrid Module Definition" in a "CRM" web application is the "Search Companies by keyword" Page. In our "CRM" web project, you have the Domain Model containing the "Company" entity, the "Sales Manager" and "Administrator" site view and two "Module Definition Views", one for the "Action" and the other for the "Module". The search features must be available both for "Sales Manager" and "Administrator" users, but they have access to a different Site View of the Web Project. Without using the "Module" concept, to provide both roles the same feature you would model the same page twice, as you can see.

How to Refactor into a Hybrid Module Definition

Let’s see how to change the previous model in order to use a module referencing a "Hybrid Module Definition". Let’s select the IFML model we want to add to the "Hybrid Module Definition". In our example it’s enough to select the "Search Companies by keyword" page, in the "Sales Manager" site view. Right-click on the element, select the "Refactor" and then "Transform into Module.." option. In the opening dialog select the "Module Definitions View" where we want to create the "Hybrid Module Definition". Then press the "Next" button. The next step requires us to provide a meaningful name for the "Hybrid Module Definition", such as "Search for Companies". Then press "Finish" to confirm the operation.

The result of this operation is that the page we chose before is substituted with a "Module" element, which references the "Hybrid Module Definition" automatically created by WebRatio Platform. To see the "Hybrid Module Definition" select the "Module" element, move to the Properties View and press the "Jump to Module Definition" button next to the "Module Definition" property. This takes us inside the referenced "Hybrid Module Definition".

How to Reuse a Hybrid Module Definition

Now that we have the "Module Definition", it’s possible to replace every place where we use the same model, with the module. Select the "Search Companies by keyword" Page in the "Administration View", right-click and choose the "Delete" option. Now you can add a module that references our "Hybrid Module Definition".

Select the "Module" icon in the "Container" section from the toolbar and click in the work area. In this case the Module is directly associated to the "Search for Companies" hybrid module definition, because there is only one "Hybrid Module Definition" in the "Module Definition View". But if there is more than one "Hybrid Module Definition" in the "Module Definition View", we must associate the instance of the module to the correct "Hybrid Module Definition". Then select the "Module" in the "Site View" and move to the Properties View. Press the "Select" button next to the "Module Definition" property and, in the opening dialog, select the "Module Definition" you want to reference. Press the "OK" button to confirm.

How to Add a Hybrid Module Definition

It is also possible to model a "Module Definition" starting from scratch, not only from an existing model.

Let’s see how to model a "Hybrid Module Definition". In our "CRM" web project, move to a "Module Definitions CRM" view created previously. Select the "Hybrid Module Definition" from the toolbar and click in the work area. Go to the "Properties View" and give a name to the "Hybrid Module Definition ". In the work area, double-click on the "Hybrid Module Definition" to open the definition and create the model.

Module Definition Structure

Now that you know how to create a module definition, let’s have a look at the structure of a "Module Definition". Let’s consider the "Hybrid Module Definition" containing the "Search Companies by keyword". The skeleton of the definition consists of these main elements: an "Input Port", one or more "Output Ports" and a portion of an IFML model. In the "Content Module" you can only use the "Output Ports", while in the "Hybrid Module", you can only use the "OK Ports" and "KO Ports".

Ports

There are four available types of Ports.

Input Port

An interaction point between a Module/Action and its environment that collects interaction flows and parameters arriving at the Module/Action. On the "Input Port", it’s possible to have parameters defined that can pass to the Components present in the Module.

Output Port

An interaction point between the Module/Action and its environment that collects the interaction flows and parameters going out from the Module/Action.

OK Port

An Output Port of an Action Definition that represents the success of the action’s execution.

KO Port

An Output Port of an Action Definition that represents the failure of the Action’s execution. The "Output Ports" can have parameters that you can pass out of the Module.