model the domain objects
If you are going to create an object
to represent a real life entity inside your OBEROn application then
you must define first which are the characteristics for this object
and actions that can be done with it. In other words, each object
is an instance of a well-defined object model and it is described
by an object class.
A class identifies a kind of application object and the collection
of properties that characterize it. Like for an object programming
language, a class is a model composed of attributes (or fields)
that collect the object data and methods that operate on that data.
Object classes are basically defined by the fields
they contain. Objects may have fields such as dimensions, volume,
weight, color, materials, shape and so on.
You can define a field as a characteristic of a class of object
or of a link between two objects. For example, assume the object
is a movie. It might have attributes such as author, director, producer,
duration time, date of publication, etc.
When an object is created, the user specifies the object class and
so he can introduce the field values for that object instance. The
specific value for each field can be different for each object instance;
however, all objects of the same class have the same fields.
A class can be derived from another
class or in other terms it extends this class. This means that the
extended class is of the same kind as its parent (called SuperClass).
For example, a thriller is a kind of movie which in turn is a type
of media. The structure of derived classes is called a class hierarchy.
Extended classes inherit characteristics from their parent classes
and in particular they have at minimum the same fields and methods
in addition to the own ones. This concept is called field/method
inheritance.
Best practice is to create first the basic classes and then derive
the extended ones. A class can be also defined Abstract or
non-Abstract: abstract classes are like subset of properties
for other extended classes. They are useful only in defining characteristics
that are inherited by other object classes, but cannot be used to
create any object instances. At the contrary, non-abstract classes
can be used to create instances of business objects.
Users enabled
to manage Classes (see user
access rights )
can create a new class instance by clicking the "Add
new Class" button from the "Context Design" menu
and compile the relative form.
The same users should also have access to create Field
instances to add to the new class.
When you define a field, the Type
option is always required: it identifies the type of values the
attribute will have. A field can assume seven different types of
values:
|
string |
A variable character
array with maximum length equal to 255 |
|
text |
A Character Large
Object (CLOB) |
|
integer |
A signed integer
value included between -231 and +231-1 |
|
real |
A signed double
precision value |
|
boolean |
The only permissible
values for a boolean variable are "true" and "false"
(or empty if not set) |
|
date |
A date with ISO
format: "yyyy-MM-dd" |
|
datetime |
A date/time value
with format: "yyyy-MM-dd HH:mm" ,
"yyyy-MM-dd HH:mm:ss" (time is related to default
GMT TimeZone) or
"yyyy-MM-dd HH:mm:ss TMZ" (where TMZ is the TimeZone) |
Once a type is assigned to a field, it can be changed,
but in some cases this operation causes a loss of information.
You can also define a Default value for the field. When a
business object is created and you don't set the field value, the
default value is assigned. When assigning a default value, the value
you give must agree with the attribute type. You you set the default = today for date and datetime field types, the value will be set automatically to the object/link creation date(time).
Real values are usually expressed on some kind of Unit
Measure; when a unit measure for a real field is selected, OBEROn
will use the standard international (SI) metric system to represent
the value inside the database. Alternative unit measures can be
associated to a real field, but their usage depends on the user
default metric system. In other terms, if a field allows an alternative
UM and this UM is included into the user's metric system, the field
value will be converted from the SI unit to the user unit during
the read operation and converted back from the user unit to the
corresponding SI unit during the save/write operation.
Also the date and datetime types can have an associated unit measure, but in this case it represents the date format.
The
Reset option represents the behaviour of the field value when the object instance is cloned or revised; there are the following settings:
Option |
Behaviour |
none |
the value is copied to the new instance |
onclone |
the value is reset to the default value only for the clonation operation |
onrevise |
the value is reset to the default value only for the revision operation |
oncreate |
the value is always reset to the default |
In addition you can define the Range of
values the field can assume. When a field has a specific range,
any value the user tries to assign to that field is checked to determine
if it is within that range. Only values that respect the defined
range are allowed. The default value must also be valid for the
defined ranges.
There are two types of range values: some are or inclusive operators
while other are constraints. A value is valid if respects all the
defined constraints and at least one of the defined conditions (or
possible values) in the range list.
Operator
|
Symbol
|
Description
|
Possible values |
|
|
equal
|
=
|
field value can be equal to this value |
closed interval
|
[ ; ]
|
field value can be included into the interval
or equal to the extreme values |
left opened interval
|
( ; ]
|
field value can be included into the interval
or equal the maximum value |
right opened interval
|
[ ; )
|
field value can be included into the interval
or equal the minimum value |
opened interval
|
( ; )
|
field value can be included into the interval,
extreme values are excluded |
Constraints |
|
|
not equal
|
!=
|
field value must be different to this value |
less than
|
<
|
field value must be less than a specified value |
greater than
|
>
|
field value must be greater than a specified value |
less than or equal
|
<=
|
field value must be less than or equal to the
specified value |
greater than or equal
|
>=
|
field value must be greater than or equal to the
specified value |
When a field has the "Multiple
Values" option active its value can be the concatenation
of more values separated by the comma character (",")
and each value must be valid respect to the range list as seen above.
You can create a field with an OOQL
command
like the following:
field
define 'Rating' type string |
|
description
'Content suitability for certain audiences'
range = 'G-GeneralAudiences' |
|
|
= 'PG-ParentalGuidanceSuggested'
= 'PG13-ParentStronglyCautioned'
= 'R-Restricted'
= 'NC17-NoUnder18' |
|
default
'G-GeneralAudiences' |
|
reset none ; |
To complete the Movie class creation, you can search
the fields just created into the "Fields" tab of the class
form and add them.
The equivalent OOQL
command
is:
class
define 'Movie' abstract |
|
description
'Define movie objects'
field 'Author' 'DurationTime' 'Producer' 'Rating' ; |
As the "Movie" class is abstract you cannot
instantiate objects of this kind and you have to define at least
one extended class derived from it. For example, you can introduce
a classification by genre and define a sub-class for each type of
movie: Comedy, Romance, Horror, Thriller, Drama and so on.
class
define 'Horror' extend 'Movie' |
|
description
'Define movie of Horror genre'
field 'HorrorType' ; |
For a particular type of movie you might need more
fields to accurately describe the content. For example, over the
years horror movies have been divided in different categories: one
classification finds them as supernatural, scientific and naturalistic
movies. The field HorrorType is added to the inherited ("H")
fields from the basic Movie class.
field define 'HorrorType'
type string
|
|
description
'The horror classification'
range = 'Supernatural' = 'Scientific' = 'Naturalistic' ; |
class edit 'Horror' field add 'HorrorType' ; |
|