 |
Fully qualified names and leading dot notation |
◂ Prev
Next ▸
Fully Qualified Names
This section introduces important information about how model elements are named in World Modeler. Recall from the
Introduction topic that models are a hierarchy of element types (Packages, EntitiyDefinitions, AttributeDefinitions, Formulas,
and so on). Each of these has a simple name that is descriptive of what the model element represents. However, these simple names are not necessariy
unique in the model. For example, suppose we have a model that includes both a package for representing a cash-on-hand ledger, and a different package
for representing outstanding loans. Both a ledger and a loan may have an attribute named "Balance", representing the positive cash value of the ledger, and
the amount outstading of the loan. But if they are both called "Balance", how can World Modeler (or us, for that matter), tell them apart?
Model hierarchy
|
The answer lies in the model hierarchy, and uses a technique that is common in modern computer languages called
name qualification. This allows unique names to be constructed by
pre-fixing to the element's name the path through the model hierarchy, from the model root to the element's parent, itself. We call this
the Fully Qualified Name of the element, and in the case of the "Balance" example in the previous paragraph, it would look like this.
FinanceModel.ModelRoot.Cashflow.Ledger.Balance //Ledger Balance
FinanceModel.ModelRoot.Liabilities.Loans.Balance //Loan Balance
|
The above terms are the fully qualified names of the two "Balance" Attributes. In general, the fully qualified name of any model
element is determined from the following template:
Model Name.Root Package Name.Sub-package Name(s).↰ Entity Name.Attribute Name.Formula Name
where the ↰ symbol implies that the preceding term may occur several times as the hierarchy tree is traversed (specifically, that there may
be several layers of Sub-packages in the hierarchy).
Within World Modeler's execution engine,
all model elements are represented by their fully qualified names, so there is no possibility of ambiguity if two elements have
the same name in different parts of the model. In general, when referring to model elements, using fully qualified names will
ensure that the intended variable is the one being referred to in a model expression.
However, fully qualified names are a lot to type and they have other drawbacks as well. The following section addresses how
World Modeler provides some short-cuts that help with this.
|
Unqualified and Entity qualified Attribute Names
To save typing, World Modeler allows Attribute names to be used without any qualification if those names are unique in the model (if they are not,
an error will be raised). So, for example, had we only had a single "Balance" Attribute in our model fragment, above, or had we called the two
"Balances" "LoanBalance" and "LedgerBalance", then we would be able to refer to them with just their name and an expression such as
LedgerBalance + LoanBalance would be perfectly legal. We call such
unique names
Unqualified Names.
Unqualified names save typing in one sense, since the entire fully qualified name doesn't need to be written out, but in more complex models,
they do tend to result in very long Attribute names. Because of this, World Modeler offers a compromise solution. The "Balance" example with
which we begain this topic is very common. There are two Attributes with the same name belonging to different parent Entities. Since, in
practice, it is very rare that the two Entities also have the same name, in almost all cases, specifying
Entity.Attribute is
enough to uniquely identify the Attribute in the model. Therefore, World Modeler also permits model Attribute names to be written
in their
Entity Qualified form. In the case of our "Balance" Attributes above, this is:
Ledger.Balance //Ledger Balance
Loans.Balance //Loan Balance
Leading dot notation
As a final convenience, World Modeler allows the leading Model name and Root Package names to be omitted from the fully qualified name
of any model element contained in the model hierarchy. The general template is:
.Sub-package Name(s).↰ Entity Name.Attribute Name.Formula Name
There are two reasons for this:
- Within a single model, the Model name and Root Package name are always the same, so explicitly including them does not
add any information to identifying the element in question.
- Specifying the name of a model element relative to the root of the model it belongs to makes models much more modular.
a relative reference can be copied or moved into a different model and still work without modification.
We refer to this "relatively qualified" format as the
leading dot notation, because the first character in this kind of
name is the "dot" or period (.). Writing the names of the Attributes in the "Balance" example, above, in leading dot notation gives us:
.Cashflow.Ledger.Balance //Ledger Balance
.Liabilities.Loans.Balance //Loan Balance
Which notation should I use, and when?
You may use any of the notations:
Fully qualified
(any type of entity)
Unqualified
(Attribute only)
Entity qualified
(Attribute only)
leading-dot
(any type of entity)
as appropriate for the model element being referred to at any time. World Modeler will automatically determine which notation you are
using and resolve the name if it can.