Model
A model is a collection of type definitions and execution (business) logic belonging to the same domain. Every model file must start with the definition of the model name.
The model
keyword is used to start a model definition.
Syntax:
model <fq-name> ;
where the <fq-name> is the fully qualified name of the model. The fully qualified name consists of optional namespaces and the name of the model separated by double colons (::
), for example judo::example::shop
. shop
is the name of the model and the namespaces are judo
and example
.
Namespace
Namespace is a naming hierarchy built from the names of the container namespaces starting at the root of the hierarchy.
Examples:
model judo::example::shop;
model shop;
Import
To import an other model into your model, we need to use the import
keyword which is used to access model and its types into the current model. Use import to access built-in and user-defined models into your model file.
The import statement is not transitive. Thus, if model B imports model A and model C imports model B, then elements of model A are not available in model C. To access elements of model A in model C, model C must also import model A. In other words, each model files must be explicitly imported to access its elements.
To import an existing model, use the import
keyword.
Syntax:
import <model> [as <alias>] ;
where the <model> is the fully qualified name of the imported model.
Examples:
import judo::types;
import judo::types as types;
If the imported model is accessed successfully, it will be made available in the local namespace in one of two ways:
-
If the model name is followed by
as
, then the alias name followingas
is bound directly to the imported model.
Example:
import judo::types as types;
entity Person {
field types::String firstName;
}
-
If no alias is specified, the elements defined in the imported model are directly accessible, so your statements can directly refer to the imported model elements using their names.
Example:
import judo::types;
entity Person {
field String firstName;
}
Notice the difference between the field declarations in the examples above.