Models
A model is a definition of a container, which represents the functionality or knowledge about some kind of entity. At run time, a model can be instantiated into model instances. Models are defined by Thing Definition Language (TDL).
In general, there are three types of models in an IoT application:
- ThingModel - representing any entity external to the system that can have interactions with the system (e.g. exchanging messages). These "things" can be sensors, actuators, machines, or other devices.
- DataModel - representing a data structure.
- AppModel - representing any unit of application logic which can contain one or more processes. These processes may interact with other components within the system (e.g. other Models) or with external applications.
The basic structures of Models
- A name
- A list of Attributes
- A number of Actions (only ThingModels and AppModels have Actions)
- A number of Constraints (including Unique)
All models by default contain an Attribute of type SystemId (or Sid). If Sid is not defined by the author of the model, system will assign Sid to the model.
Model "combines" model facets
To increase reusability, model facets are adopted as reusable units.
There are two types of model facets:
- ThingFacets
- AppFacets
Model facets have the same structural components of Models (name, attributes, actions, constraints). However, model facets are not instantiated or persisted. They can only be "combined" as part of a model, with the model being instantiated, and persisted.
- ThingModel can combine ThingFacets;
- AppModel can combine AppFacets;
- There is no DataFacets.
As a good and recommended practice pattern, actions and attributes of a particular device logic or application logic are always defined in the model facets, and the model will acquire those attributes and actions via the keyword "combines". A model can combine multiple model facets. And vice versa, model facet can by combined by multiple model definitions.
For example:
# ThingModel(Name: "TempSensor", combines: "TempFacetSerial"): Sid(Name: "sensorId");