Home > Metamodelling Concepts > Inferred Field
Classes, attributes and associations describe the structure of the information which is finally stored within the database.
In contrast inferred fields can be inferred from that information. Please have a look at the following class definition:
@entity class Person {
@attribute Natural yearOfBirth;
@inferred Natural age() {
return java.util.Calendar.getInstance().get(java.util.Calendar.YEAR) - getYearOfBirth();
}
}
The attribute "yearOfBirth" is stored within the database. The inferred field "age" is computed on behalf of the already available persistent information.
It is not a good option to store the age as a second attribute as you would then be responsible for the management of redundant information within persistent storage. On the other hand it isn't sufficient to code a method "getAge()", because then the database back-end cannot know that it might be a good idea to materialize the computable information in the database as well - for performance reasons. Therefore you should model "age" as an inferred field (as shown above).
Inferred fields can be used within database queries.
In SDL inferred fields are represented as Java methods - they are marked with the annotation @inferred. Please note that these "methods" must not have a single parameter. Moreover the return type is always an OOMEGA type.
Next chapter: Method