This page describes advanced EXPRESS concepts, including features introduced by EXPRESS edition 2.
EXPRESS Edition 2 (2004) introduced EXTENSIBLE types. These are SELECT and ENUMERATION types whose item lists can be extended. This provides increased flexibility and reuse in modeling.
In some sense, EXTENSIBLE types are analogous to SUBTYPEs, except that subtyping reduces the domain while extending increases the domain.
SELECT specifies a list of things to choose from
ENUMERATION specifies a list of items (names)
It is possible to extend these lists
TYPE approval = EXTENSIBLE ENUMERATION OF (approved, rejected); END_TYPE; TYPE your_approval = ENUMERATION BASED_ON approval WITH (cancelled); END_TYPE; TYPE my_approval = EXTENSIBLE ENUMERATION BASED_ON approval WITH (pending); END_TYPE;
Constraints and relationships
If one entity serves as an attribute of another entity, then the two entities are related, or more precisely there is a relationship between the two entities.
When an attribute of an entity is of type entity, then a relationship is established between the two entity types.
ENTITY door; hinges : SET [2:?] OF hinge; knob : handle; ... END_ENTITY; ENTITY hinge; id : name; ... END_ENTITY; ENTITY handle; ... END_ENTITY;
The relationships established here are:
doormust have at least two
doormust have a
Cardinality is how many of one thing is needed/used by another thing.
|‘Cardinality’ is related to ‘cardinal number’ — a number used for counting.|
The cardinality of the ‘attribute’ entity with respect to the ‘owning’ entity is defined in the owning entity. Cardinality constraint from the referring entity to the referenced entity is specified via the attribute definition (e.g OPTIONAL, aggregation).
By default, the cardinality of the owning entity with respect to the
attribute entity is zero to many (
INVERSE attributes can be used to specify other cardinalities.
In the last model, a
door required one
handle but from the point of view of
handle, any number could be used on a
door (or this could be restated as
handles know nothing about
In this model a
handle can be used on either one or no doors.
ENTITY door; hinges : SET [2:?] OF hinge; knob : handle; ... END_ENTITY; ENTITY handle; ... INVERSE knob_for : SET [0:1] OF door FOR knob; END_ENTITY;
Here, the INVERSE clause states that a handle is ‘used’ by zero or one doors.
Subtypes and supertypes
The abstract entity was introduced in EXPRESS Edition 2, as an ENTITY that can only be instantiated via its SUBTYPEs.
It has to be instantiated (e.g., appear in a Part 21 file) via a SUBTYPE in which the specific type of each attribute is specified.
ENTITY general_approval ABSTRACT; approved_items : SET OF GENERIC_ENTITY; status : approval_status; END_ENTITY;
The model here says that a
general_approval has a
status which is of type
approval_status (whatever that is), and
approved_items (which is a SET of
An instantiable SUBTYPE would have to replace
GENERIC_ENTITY by a named
plan (whatever that might be), to have a set of approved
GENERIC_ENTITYstands for any
All attributes must have specific types before instantiation is possible.
An attribute type can be re-declared to a more specific kind in a SUBTYPE
The database world talks about IS-A relationships, for instance,
THIS IS-A THAT, or
A CAR IS-A (kind of) VEHICLE.
a SUBTYPE IS-A (more special kind of its) SUPERTYPE(s);
a SUPERTYPE IS-A (more general kind of its) SUBTYPE(s).
EXPRESS supports the IS-A relationship via subtyping.
For example, Entities S1, S2, … can be declared to be SUBTYPES of entity E. This also effectively declares E to be a SUPERTYPE of S1, S2, etc.
That is, S1 is-a E, S2 is-a E, etc. Also, E may-be an S1, E may-be an S2.
An entity may be both a SUB- and a SUPERTYPE.
An entity may be a SUBTYPE of more than one entity.
SUPER/SUBTYPING may be used for many purposes.
The ‘meaning’ of SUBTYPE:
A Subtype is a specialization of its Supertype(s).
New attributes may be added.
New constraints may be added.
Attributes may be ‘retyped’ (i.e their domains may be specialized in a compatible manner).
The following example includes examples of the last 3 elements in the list.
ENTITY circle; radius : NUMBER; center : point; END_ENTITY; ENTITY specialised_circle SUBTYPE OF (circle); SELF\circle.radius : REAL; -- retyped shade : colour; -- additional attribute WHERE SELF\circle.radius > 3.0; -- add constraint END_ENTITY;
This example shows:
A SUBTYPE is a special kind of its SUPERTYPE(s). There are fewer instances of a SUBTYPE than of its SUPERTYPE. For example, there are fewer CARS than there are VEHICLES.
A SUBTYPE inherits all the attributes and constraints of its SUPERTYPE(s).
A SUBTYPE can have additional attributes and constraints.
Given the original information model:
ENTITY person; first_name : STRING; last_name : STRING; nickname : OPTIONAL STRING; ss_no : INTEGER; gender : sex; spouse : OPTIONAL person; children : SET [0:?] OF person; UNIQUE un1 : ss_no; WHERE w1 : (EXISTS(spouse) AND gender <> spouse.gender) OR NOT EXISTS(spouse); END_ENTITY;
This following revised
person model eliminates the original WHERE rule about
spouses being of opposite sex. We can also talk about a
person without having
to identify the person’s gender.
ENTITY person; first_name : STRING; last_name : STRING; ss_no : INTEGER; children : SET [0:?] OF person; UNIQUE un1 : ss_no; END_ENTITY; ENTITY male SUBTYPE OF (person); wife : OPTIONAL female; END_ENTITY; ENTITY female SUBTYPE OF (person); husband : OPTIONAL male; END_ENTITY;
Subtype instance constraints
In general, an instance of a Supertype may involve instances of zero or more of its Subtypes.
If this is not the required behaviour, then the ‘instance set’ can be constrained.
ENTITY person; ... END_ENTITY; ENTITY employee SUBTYPE OF person; ... END_ENTITY; ENTITY student SUBTYPE OF person; ... END_ENTITY;
We can use this model to talk about:
A person who is an employee
A person who is a student
A person who is an employee and who is also a student
The SUBTYPE_CONSTRAINT construct was introduced in EXPRESS Edition 2.
In Edition 1, the constraint specification was lexically embedded in the definition of the Supertype entity. If a new subtype was introduced in a different Schema that imported the Supertype there was no convenient method, apart from changing the original Supertype definition, of constraining the use of the new Subtype.
In general, an instance of a Supertype can involve any of its Subtypes.
The constraints are used to eliminate certain combinations of Subtypes.
Multiple SUBTYPE_CONSTRAINTs can be applied to a Supertype. The constraints are additive. (In EXPRESS you cannot eliminate a constraint).
This model specifies SUBTYPE constraints for ENTITY
SUBTYPE_CONSTRAINT sc FOR ent; -- constraints END_SUBTYPE_CONSTRAINT;
SUBTYPE_CONSTRAINT can be used with:
No constraints: An instance of the Supertype involves zero or more Subtype instances.
ABSTRACT SUPERTYPE: An instance of the Supertype must involve one or more Subtype instances.
TOTAL_OVER(x,y)means that every instance of the Supertype must involve an instance of at least one of the listed Subtypes.
ONEOF(x,y,z)means that one and only one of the listed Subtypes can be instanced with an instance of the Supertype.
(x ANDOR y)means that an instance of the Supertype may be accompanied by instances of the Subtypes x and/or y (the default condition).
(x AND y)means that an instance of the Supertype may be accompanied by instances of the Subtypes x and y.
An ABSTRACT SUPERTYPE can only be instantiated in conjunction with non-ABSTRACT subtype(s).
An entity does not have to declare itself to be a SUPERTYPE. It is a SUPERTYPE if it is mentioned by a SUBTYPE.
In some cases, a Supertype is not to be instantiated without one of its Subtypes. The entity can be constrained to be an ABSTRACT SUPERTYPE.
ENTITY mammal ... END_ENTITY; SUBTYPE_CONSTRAINT sc_abs FOR mammal; ABSTRACT SUPERTYPE; END_SUBTYPE_CONSTRAINT; ENTITY dog SUBTYPE OF mammal; ... END_ENTITY;
This was introduced in Edition 2.
|I have failed to find any use for it.|
It means (I think) that the listed Subtypes completely cover the domain of the Supertype. Further, every instance of the Supertype that includes Subtype instances must include an instance of one of the listed subtypes.
ENTITY person; ... END_ENTITY; SUBTYPE_CONSTRAINT adultchild FOR person; TOTAL_OVER(adult,child); END_SUBTYPE_CONSTRAINT; ENTITY child SUBTYPE OF (person); END_ENTITY; ENTITY adult SUBTYPE OF (person); END_ENTITY; ENTITY student SUBTYPE OF (person); END_ENTITY;
In this model, every person is either a child or an adult. A student is also either a child or an adult.
A ONEOF constraint means that one and only ONE OF the listed subtypes can be used in an instance of the Supertype.
ENTITY person; first_name : STRING; last_name : STRING; ss_no : INTEGER; children : SET [0:?] OF person; UNIQUE un1 : ss_no; END_ENTITY; SUBTYPE_CONSTRAINT mf FOR person; ONEOF(male, female); END_SUBTYPE_CONSTRAINT; ENTITY male SUBTYPE OF (person); wife : OPTIONAL female; END_ENTITY; ENTITY female SUBTYPE OF (person); husband : OPTIONAL male; END_ENTITY;
Here the constraint is that a person cannot be simultaneously a male and a female. Note that if the constraint was not there (as in the earlier model) it would mean that the model catered for hermaphrodites, which would introduce a new set of problems.
P ANDOR Q means that the following combinations of subtypes are allowed:
P and Q together.
That is, P and/or Q are allowed.
The unconstrained relationship between Subtypes (the default) is ANDOR.
ENTITY person; first_name : STRING; last_name : STRING; ss_no : INTEGER; children : SET [0:?] OF person; UNIQUE un1 : ss_no; END_ENTITY; SUBTYPE_CONSTRAINT es FOR person; employee ANDOR student; END_SUBTYPE_CONSTRAINT; ENTITY employee SUBTYPE OF (person); salary : REAL; END_ENTITY; ENTITY student SUBTYPE OF (person); fees : REAL; END_ENTITY;
In this example model, the constraint might as well not be there.
P AND Q means that if there is an instance of P it must be accompanied
by an instance of Q, and vice-versa — either both or none.
ENTITY person; ... END_ENTITY; SUBTYPE_CONSTRAINT mf_and_ca FOR person; ONEOF(male, female) AND ONEOF(citizen, alien); END_SUBTYPE_CONSTRAINT; ENTITY male SUBTYPE OF (person); ... END_ENTITY; ENTITY female SUBTYPE OF (person); ... END_ENTITY; ENTITY citizen SUBTYPE OF (person); END_ENTITY; ENTITY alien SUBTYPE OF (person); END_ENTITY;
This example shows that the constraints may be complex (logical) expressions.
Unconstrained there are 15 possible combinations (from Person to a male, female, citizen, alien person).
With the given constraints there are only 5 (Person, (fe)male citizen, (fe)male alien).
Global constraints and expressions
Now we are getting away from structural modeling.
The query expression evaluates a logical expression against each element of an aggregation, returning an aggregation of all the elements for which the logical expression is TRUE.
The syntax is roughly:
QUERY( temp <* agg | lexp)
temp is the name of a temporary variable,
agg is the
lexp is the logical expression.
Assuming that a person’s attributes included the age of the person,
QUERY(t <* persons | t.age >= 21)
would return all the people whose age was 21 or greater.
You can’t actually write this function in EXPRESS (if you could the QUERY expression would probably not have been invented), as there is no LOGICAL_EXPRESSION type in the language.
An example of its use follows.
The effect of QUERY is similar to the pseudo-function below.
FUNCTION q(agg : AGGREGATE OF GENERIC; lexp : LOGICAL_EXPRESSION;) : AGGREGATE OF GENERIC; LOCAL result : AGGREGATE OF GENERIC := ; END_LOCAL; REPEAT i := 1 TO SIZEOF(agg); IF (lexp = TRUE) THEN result := result + agg[i]; END_IF; END_REPEAT; RETURN(result); END_FUNCTION;
Local constraints (WHERE, UNIQUE, INVERSE) are applied to each and every instance of the entity.
Global constraints (RULEs) are applied between entities or across a subset of entity instances.
A WHERE rule in an ENTITY applies to each and every instance of the ENTITY.
A RULE is a constraint that can be applied to either some instances of a particular ENTITY or to combinations of instances of different ENTITY (types).
Given a database of instances, each RULE is applied to every applicable instance in the database to determine if the instance conforms to the constraint.
EXPRESS assumes that every (ENTITY) instance has a unique identifier,
although it does not specify what that might be. You could have two (or more)
instances of a
point with the same coordinate values but they are
still distinguishable from each other in the storage system.
The following rule states that there shall be one and only one point at the origin in the objectbase.
RULE unique_origin FOR (point); LOCAL origin : BAG OF point; END_LOCAL; origin := QUERY(temp <* point | (temp.x = 0.0) AND (temp.y = 0.0) ); WHERE r1 : SIZEOF(origin) = 1; END_RULE;
Creating a robust EXPRESS model is not necessarily easy.
Going back to the person/male/female model, it does say that wifes are females and husbands are males. It doesn’t say that if Adam claims his wife to be Eve then Eve’s husband must be Adam.
In some communities that might not be a problem. But, if it is in the bit of the real world that the model represents, then the rather complicated RULE fixes that relationship problem.
It looks at every male and checks to see if he is his wife’s husband. It also has to look at every female to see if she is her husband’s wife.
The double check is needed for the cases when one of a pair claims to be single.
|EXPRESS does not specify when the RULEs should be checked.|
This RULE states that husbands and wives must be married to each other.
RULE married FOR (male,female); LOCAL ok1, ok2 : BOOLEAN := TRUE; END_LOCAL; IF (EXISTS(male.wife) AND male :<>: male.wife.husband) THEN ok1 := FALSE; END_IF; IF (EXISTS(female.husband) AND female :<>: female.husband.wife) THEN ok2 := FALSE; END_IF; WHERE r1 : ok1; r2 : ok2; END_RULE;
Working with external schemas
An EXPRESS model typically consists of several SCHEMAs, each dealing with a distinguishable subtopic.
Definitions within a Schema are potentially available to all Schemas. Anything in a SCHEMA can be utilised by any other SCHEMA — you can’t hide anything — but you have to specify what you want.
Definitions have to be ‘imported’ from the original Schema into the ‘current’ Schema. The imported definition implicitly imports all the necessary definitions to complete the definition.
The contents of a SCHEMA are ENTITY, TYPE, RULE, SUBTYPE_CONSTRAINT, FUNCTION, PROCEDURE and CONSTANT declarations, each of which has a name.
Within a SCHEMA all the names must be unique.
When importing something from another SCHEMA it may be necessary to rename it if its name is already declared, or it may convey the semantics better if it was called by a different name.
EXPRESS syntax is roughly:
import FROM schema_ref (def1 AS newname1, def2 AS newname2);
Only ENTITYs and TYPEs can be imported via a USE statement.
ENTITYs are ‘first class’ items. That means that in the object base
instances do not need to be referenced by other instances (i.e they can be
Any items needed to complete the definitions of an imported item via USE are implicitly REFERENCEd into the schema.
If no list is given, all ENTITYs and TYPEs in the SCHEMA are imported.
It is as though the ENTITY had been declared in the using schema. Following from this, USEs can be chained.
fc is a first-class entity, then the statement
SIZEOF(USEROF(fc)) >= 0;
Here is a demonstration 2-schema model where an entity declared in one schema is USEd by the other.
Following this is an equivalent model expanding out the USE.
SCHEMA source; ENTITY e1; attr : t1; END_ENTITY; TYPE t1 = REAL; END_TYPE; END_SCHEMA; SCHEMA using; USE FROM source (e1); ENTITY e2; attr : SET OF e1; END_ENTITY; END_SCHEMA;
In the expanded model, SCHEMA
source is unchanged.
using is changed with the USE being replaced by:
t1is REFERENCED from SCHEMA
sourceto provide for the
e1(which was originally implicitly referenced).
SCHEMA source; ENTITY e1; attr : t1; END_ENTITY; TYPE t1 = REAL; END_TYPE; END_SCHEMA; SCHEMA using; REFERENCE FROM source (t1); ENTITY e1; attr : t1; END_ENTITY; ENTITY e2; attr : SET OF e1; END_ENTITY; END_SCHEMA;
Effectively, any kind of item can be REFERENCEd — ENTITY, TYPE, FUNCTION …
REFERENCEd ENTITYs are second class items (only instances that are used as attribute(s) in other ENTITYs are allowed).
Items required to complete declarations are implicitly REFERENCEd, but there is no chaining.
A REFERENCE with just the SCHEMA name references everything in the SCHEMA.
If an item is both USEd and REFERENCEd, it is treated as being USEd.
Any kind of item can be imported via a REFERENCE statement.
A REFERENCE is necessary to resolve references (links) to declarations in other schemas.
REFERENCEDd items are ‘second class’ items (i.e they can not be independently instantiated).
The ‘stuff’ required to complete the definitions of an imported entity are implicitly REFERENCEd into the schema.
sc is a second-class entity, then the statement
SIZEOF(USEROF(sc)) >= 1;
This model is the same as the earlier one except that USE is replaced by REFERENCE.
An expanded version follows.
SCHEMA source; ENTITY e1; attr : t1; END_ENTITY; TYPE t1 = REAL; END_TYPE; END_SCHEMA; SCHEMA referencing; REFERENCE FROM source (e1); ENTITY e2; attr : SET OF e1; END_ENTITY; END_SCHEMA;
In the expanded model, SCHEMA
source is unchanged.
using is changed with the REFERENCE list expanded
to include the TYPE
t1 (which was originally implicitly
SCHEMA source; ENTITY e1; attr : t1; END_ENTITY; TYPE t1 = REAL; END_TYPE; END_SCHEMA; SCHEMA referencing; REFERENCE FROM source (e1, t1); ENTITY e2; attr : SET OF e1; END_ENTITY; END_SCHEMA;
Extensions or constraints using external schemas
A SCHEMA can extend and/or constrain a model in another SCHEMA.
bbb (which is
aaa under another name) and
are first class entities. Entity
original, which is now a SUPERTYPE of
constrained, is second class (every instance of
original must also be an
original does not know it is a SUPERTYPE as
first knows nothing about the
SCHEMA first; ENTITY aaa; -- attributes END_ENTITY; ENTITY original; attr : NUMBER; END_ENTITY; END_SCHEMA; -- first SCHEMA second; USE FROM first (aaa AS bbb); REFERENCE FROM first (original); ENTITY constrained SUBTYPE OF (original); attr : INTEGER(7); WHERE positive : attr > 0; END_ENTITY; END_SCHEMA; -- second