Table of Contents
In an app, we have to deal with various types of attributes. While
many of them have a standard datatype, like Integer
or
String
, as their range, some of them may have special datatypes
as their range. For instance, the Universal Business
Language (UBL), which is an industry standard defining document
formats for electronic commerce, defines a large set of business datatypes
including the following.
UBL Data Type | Description |
---|---|
Date | One calendar day according to the Gregorian calendar. |
Time | An instance of time that occurs every day. |
DateTime | A particular point in the progression of time, together with relevant supplementary information. |
Percent | Numeric information that is assigned or is determined by calculation, counting, or sequencing and is expressed as a percentage. |
Amount | A number of monetary units specified using a given unit of currency. |
The Semantic MediaWiki uses the following special datatypes.
Semantic MediaWiki Data Type | Description |
---|---|
Geographic coordinate | Holds coordinates describing geographic locations |
Monolingual text | To associate a text value with a specific language code |
Quantity | Holds values that describe quantities, containing both a number and a unit |
Record | Allows saving compound property values that consist of a short list of values with fixed type and order |
Holds e-mail addresses | |
URL | Holds URIs, URNs and URLs |
Telephone number | Holds international telephone numbers based on the RFC 3966 standard |
We discuss several important cases of special datatypes and how to deal with them in the model code and in the HTML user interface code. The following class diagram illustrates examples of attributes having such a special datatype as their range.
In the C++ and C# programming communities, special datatypes like string patterns and quantities are also called "semantic types" (see, e.g., Gibson2016 and Perdeck2015).
Boolean attributes, like isSmoker
, can only have one of
two possible values: true or false, which are sometimes more naturally
expressed with yes or no. In the model code, Boolean attributes are
treated like primitive datatype attributes, since all programming
languages support Boolean as a
primitive datatype.
For rendering a Boolean attribute in a user interface, there are several options. The simplest solution is using a checkbox field. Alternatively, a single-selection list with the two options true and false (or yes and no), or a corresponding radio button group with two radio buttons, could be used.
In an HTML form, a checkbox field is implemented with an input
element of
type checkbox
. For assigning the value of the checkbox field to the Boolean
attribute, the field's checked
attribute has to be used, as shown in the following
example where we have a checkbox field in an HTML
form:
<form id="Person">
<p><label>
Is smoker: <input type="checkbox" name="isSmoker" />
</label></p>
</form>
In JavaScript code, the checkbox field is accessed via its name, and the Boolean attribute
is assigned by reading the field's checked
attribute (instead of its
value
attribute), like
so:
var isSmokerCheckboxField = document.forms["Person"].isSmoker;
var newPerson = new Person(...);
newPerson.isSmoker = isSmokerCheckboxField.checked;