Binary relations
A binary relation connects two classifiers — a source and a target — and, like a class, carries an OntoUML stereotype that fixes what kind of connection it is: a marriage's mediation of a spouse, a car's engine being a component of it, one mountain being taller than another.
A distinctive idea in OntoUML is that most relations between endurants are not
primitive — they are founded on something in the model. A «material»
relation like studies at holds only because a relator (an Enrollment)
exists and mediates the people and schools involved. So you rarely build a
material relation alone: you build the relator, its «mediation» relations,
and the material relation derived from them. The stereotypes below encode these
patterns, and the builder applies each one's default cardinalities for you.
Building a relation
Relations are built from a container — a Project or a Package — with
binaryRelationBuilder(). Pick a stereotype shortcut, name it, and set the
source and target. Both ends are required.
import { class ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project } from 'ontouml-js';
const const project: Projectproject = new new Project(): ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilderCreates a builder for a new
Package
in this project.packageBuilder().PackageBuilder.root(): PackageBuilderSets the package as the root package of its project, i.e., the package
that contains the entire model.root().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilderAdds a name to the element in the given language.name('Marriage').PackageBuilder.build(): PackageBuilds an instance of
Package
with the parameters passed to the
builder. When no methods are evoked, the created package has the
following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `contents: []`build();
const const person: Classperson = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.kind(): ClassBuilderSets the stereotype of the class to «kind», which decorates rigid
classes that provide an identity principle to their instances, which are
functional complexes (e.g., `Person`, `Car`). Also applies the following
defaults:
- `restrictedTo = [ "functional-complex" ]`
- `order = 1`kind().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Person').ClassBuilder.build(): ClassBuilds an instance of
Class
with the parameters passed to the
builder. **WARNING:** the ordering in which methods are evoked may
affect the resulting object. When no methods are evoked, the created
class has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`
- `order: 1,`
- `isPowertype: false,`build();
const const marriage: Classmarriage = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.relator(): ClassBuilderSets the stereotype of the class to «relator», which decorates rigid
classes whose instances are relators, i.e., entities that mediate other
entities and are the truthmakers of material relations (e.g.,
`Marriage`, `Enrollment`). Also applies the following defaults:
- `restrictedTo = [ "relator" ]`
- `order = 1`relator().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Marriage').ClassBuilder.build(): ClassBuilds an instance of
Class
with the parameters passed to the
builder. **WARNING:** the ordering in which methods are evoked may
affect the resulting object. When no methods are evoked, the created
class has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`
- `order: 1,`
- `isPowertype: false,`build();
// The relator mediates the people it binds…
const const husband: BinaryRelationhusband = const model: Packagemodel
.Package.binaryRelationBuilder(): BinaryRelationBuilderCreates a builder for a
BinaryRelation
contained in this
package.binaryRelationBuilder()
.BinaryRelationBuilder.mediation(): BinaryRelationBuilderSets the stereotype of the relation to «mediation», which decorates
relations between a relator and an endurant it mediates, such as a
marriage and one of its spouses. Also applies the following defaults:
- `sourceCardinality = "1..*"`
- `targetCardinality = "1"`
- `targetEnd.isReadOnly = true`mediation()
.NamedElementBuilder<BinaryRelationBuilder>.name(value: string, language?: string): BinaryRelationBuilderAdds a name to the element in the given language.name('has husband')
.BinaryRelationBuilder.source(classifier: Classifier<any, any>): BinaryRelationBuilderSets the
Classifier
connected to the source end of the relation.source(const marriage: Classmarriage)
.BinaryRelationBuilder.target(classifier: Classifier<any, any>): BinaryRelationBuilderSets the
Classifier
connected to the target end of the relation.target(const person: Classperson)
.BinaryRelationBuilder.build(): BinaryRelationBuilds an instance of
BinaryRelation
with the parameters passed
to the builder. Both the source and the target classifiers are required
before `build()` is evoked. **WARNING:** the ordering in which methods
are evoked may affect the resulting object. When no methods are evoked,
the created relation has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`build();
// …and the material relation is derived from that relator.
const const marriedTo: BinaryRelationmarriedTo = const model: Packagemodel
.Package.binaryRelationBuilder(): BinaryRelationBuilderCreates a builder for a
BinaryRelation
contained in this
package.binaryRelationBuilder()
.BinaryRelationBuilder.material(): BinaryRelationBuilderSets the stereotype of the relation to «material», which decorates
relations between endurants that are founded on relators, such as being
married to or being enrolled at. Also applies the following defaults:
- `isDerived = true`material()
.NamedElementBuilder<BinaryRelationBuilder>.name(value: string, language?: string): BinaryRelationBuilderAdds a name to the element in the given language.name('married to')
.BinaryRelationBuilder.source(classifier: Classifier<any, any>): BinaryRelationBuilderSets the
Classifier
connected to the source end of the relation.source(const person: Classperson)
.BinaryRelationBuilder.target(classifier: Classifier<any, any>): BinaryRelationBuilderSets the
Classifier
connected to the target end of the relation.target(const person: Classperson)
.BinaryRelationBuilder.build(): BinaryRelationBuilds an instance of
BinaryRelation
with the parameters passed
to the builder. Both the source and the target classifiers are required
before `build()` is evoked. **WARNING:** the ordering in which methods
are evoked may affect the resulting object. When no methods are evoked,
the created relation has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`build();
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`console.log()`** static method outputs a message to the console.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const marriedTo: BinaryRelationmarriedTo.Relation.isMaterial(): booleanChecks whether this relation is stereotyped as «material».isMaterial()); // true
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`console.log()`** static method outputs a message to the console.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const husband: BinaryRelationhusband.BinaryRelation.isMediation(): booleanChecks whether this relation is stereotyped as «mediation».isMediation()); // true
The stereotype catalog
Each shortcut sets the stereotype and applies the default meta-properties OntoUML prescribes for it (cardinalities, read-only ends, aggregation). The most common ones:
| Shortcut | Stereotype | Connects… |
|---|---|---|
.material() | «material» | endurants, founded on a relator (studies at) |
.mediation() | «mediation» | a relator and an endurant it binds |
.characterization() | «characterization» | an intrinsic aspect (mode/quality) and its bearer |
.comparative() | «comparative» | endurants compared by their qualities (taller than) |
.externalDependence() | «externalDependence» | an extrinsic mode and what it depends on |
.componentOf() | «componentOf» | a functional part and its whole |
.memberOf() | «memberOf» | a member and the collective it belongs to |
.subCollectionOf() | «subCollectionOf» | a sub-collective and its collective |
.subQuantityOf() | «subQuantityOf» | a sub-quantity and its quantity |
.participation() | «participation» | an endurant and an event it takes part in |
.termination() | «termination» | an event and an endurant it ends |
.creation() | «creation» | an event and an endurant it brings into existence |
The remaining event- and situation-related stereotypes — .instantiation(),
.participational(), .historicalDependence(), .manifestation(),
.bringsAbout(), .triggers(), and .derivation() — follow the same
pattern.
.mediation(), for instance, sets the source cardinality to 1..*, the target
to 1, and marks the target end read-only — because a relator existentially
depends on the entities it mediates. You can always override a default
afterwards (see below).
Ends and cardinality
A relation's two ends are properties, exactly like attributes — so the
same multiplicity idea applies, one bound per end. Set them on the builder with
sourceCardinality / targetCardinality, or adjust the built relation through
sourceEnd and targetEnd.
import { class ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project } from 'ontouml-js';
const const project: Projectproject = new new Project(): ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilderCreates a builder for a new
Package
in this project.packageBuilder().PackageBuilder.root(): PackageBuilderSets the package as the root package of its project, i.e., the package
that contains the entire model.root().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilderAdds a name to the element in the given language.name('School').PackageBuilder.build(): PackageBuilds an instance of
Package
with the parameters passed to the
builder. When no methods are evoked, the created package has the
following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `contents: []`build();
const const person: Classperson = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.kind(): ClassBuilderSets the stereotype of the class to «kind», which decorates rigid
classes that provide an identity principle to their instances, which are
functional complexes (e.g., `Person`, `Car`). Also applies the following
defaults:
- `restrictedTo = [ "functional-complex" ]`
- `order = 1`kind().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Person').ClassBuilder.build(): ClassBuilds an instance of
Class
with the parameters passed to the
builder. **WARNING:** the ordering in which methods are evoked may
affect the resulting object. When no methods are evoked, the created
class has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`
- `order: 1,`
- `isPowertype: false,`build();
const const school: Classschool = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.kind(): ClassBuilderSets the stereotype of the class to «kind», which decorates rigid
classes that provide an identity principle to their instances, which are
functional complexes (e.g., `Person`, `Car`). Also applies the following
defaults:
- `restrictedTo = [ "functional-complex" ]`
- `order = 1`kind().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('School').ClassBuilder.build(): ClassBuilds an instance of
Class
with the parameters passed to the
builder. **WARNING:** the ordering in which methods are evoked may
affect the resulting object. When no methods are evoked, the created
class has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`
- `order: 1,`
- `isPowertype: false,`build();
const const studiesAt: BinaryRelationstudiesAt = const model: Packagemodel
.Package.binaryRelationBuilder(): BinaryRelationBuilderCreates a builder for a
BinaryRelation
contained in this
package.binaryRelationBuilder()
.BinaryRelationBuilder.material(): BinaryRelationBuilderSets the stereotype of the relation to «material», which decorates
relations between endurants that are founded on relators, such as being
married to or being enrolled at. Also applies the following defaults:
- `isDerived = true`material()
.NamedElementBuilder<BinaryRelationBuilder>.name(value: string, language?: string): BinaryRelationBuilderAdds a name to the element in the given language.name('studies at')
.BinaryRelationBuilder.source(classifier: Classifier<any, any>): BinaryRelationBuilderSets the
Classifier
connected to the source end of the relation.source(const person: Classperson)
.BinaryRelationBuilder.target(classifier: Classifier<any, any>): BinaryRelationBuilderSets the
Classifier
connected to the target end of the relation.target(const school: Classschool)
.BinaryRelationBuilder.sourceCardinality(value: string): BinaryRelationBuilderSets the cardinality of the source end of the relation.sourceCardinality('1..*')
.BinaryRelationBuilder.targetCardinality(value: string): BinaryRelationBuilderSets the cardinality of the target end of the relation.targetCardinality('1')
.BinaryRelationBuilder.build(): BinaryRelationBuilds an instance of
BinaryRelation
with the parameters passed
to the builder. Both the source and the target classifiers are required
before `build()` is evoked. **WARNING:** the ordering in which methods
are evoked may affect the resulting object. When no methods are evoked,
the created relation has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`build();
// Equivalently, tweak the ends after building:
const studiesAt: BinaryRelationstudiesAt.BinaryRelation.sourceEnd: PropertyThe relation end at the source (first) position.sourceEnd.Property.cardinality: CardinalityThe multiplicity of this property. Defaults to `0..*`.cardinality.Cardinality.setAsOneToMany(): voidSets the cardinality to `1..*`.setAsOneToMany();
const studiesAt: BinaryRelationstudiesAt.BinaryRelation.targetEnd: PropertyThe relation end at the target (second) position.targetEnd.Property.cardinality: CardinalityThe multiplicity of this property. Defaults to `0..*`.cardinality.Cardinality.setAsOneToOne(): voidSets the cardinality to `1..1`.setAsOneToOne();
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`console.log()`** static method outputs a message to the console.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const studiesAt: BinaryRelationstudiesAt.BinaryRelation.targetEnd: PropertyThe relation end at the target (second) position.targetEnd.Property.getOppositeEnd(): PropertyRetrieves the property at the opposite end of the binary relation that
contains this property.getOppositeEnd() === const studiesAt: BinaryRelationstudiesAt.BinaryRelation.sourceEnd: PropertyThe relation end at the source (first) position.sourceEnd); // true
Read Property.getOppositeEnd() to walk from one end to the other — the basis
for navigating a model, which the Querying chapter builds on.
Parthood and aggregation
Part-whole relations mark the whole end with an aggregation kind. The
parthood stereotypes (componentOf, memberOf, …) set this for you, but you
can also apply it directly:
.composition()— a composite whole (UML's filled diamond); a part belongs to at most one whole..aggregation()— a shared whole (open diamond); a part may be shared.
import { class ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project } from 'ontouml-js';
const const project: Projectproject = new new Project(): ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilderCreates a builder for a new
Package
in this project.packageBuilder().PackageBuilder.root(): PackageBuilderSets the package as the root package of its project, i.e., the package
that contains the entire model.root().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilderAdds a name to the element in the given language.name('Cars').PackageBuilder.build(): PackageBuilds an instance of
Package
with the parameters passed to the
builder. When no methods are evoked, the created package has the
following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `contents: []`build();
const const car: Classcar = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.kind(): ClassBuilderSets the stereotype of the class to «kind», which decorates rigid
classes that provide an identity principle to their instances, which are
functional complexes (e.g., `Person`, `Car`). Also applies the following
defaults:
- `restrictedTo = [ "functional-complex" ]`
- `order = 1`kind().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Car').ClassBuilder.build(): ClassBuilds an instance of
Class
with the parameters passed to the
builder. **WARNING:** the ordering in which methods are evoked may
affect the resulting object. When no methods are evoked, the created
class has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`
- `order: 1,`
- `isPowertype: false,`build();
const const engine: Classengine = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.kind(): ClassBuilderSets the stereotype of the class to «kind», which decorates rigid
classes that provide an identity principle to their instances, which are
functional complexes (e.g., `Person`, `Car`). Also applies the following
defaults:
- `restrictedTo = [ "functional-complex" ]`
- `order = 1`kind().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Engine').ClassBuilder.build(): ClassBuilds an instance of
Class
with the parameters passed to the
builder. **WARNING:** the ordering in which methods are evoked may
affect the resulting object. When no methods are evoked, the created
class has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`
- `order: 1,`
- `isPowertype: false,`build();
const const hasEngine: BinaryRelationhasEngine = const model: Packagemodel
.Package.binaryRelationBuilder(): BinaryRelationBuilderCreates a builder for a
BinaryRelation
contained in this
package.binaryRelationBuilder()
.BinaryRelationBuilder.componentOf(): BinaryRelationBuilderSets the stereotype of the relation to «componentOf», which decorates
parthood relations between functional complexes, such as an engine being
a component of a car. Also applies the following defaults:
- `aggregationKind = "COMPOSITE"`
- `sourceCardinality = "1"`
- `targetCardinality = "1..*"`componentOf()
.NamedElementBuilder<BinaryRelationBuilder>.name(value: string, language?: string): BinaryRelationBuilderAdds a name to the element in the given language.name('has engine')
.BinaryRelationBuilder.source(classifier: Classifier<any, any>): BinaryRelationBuilderSets the
Classifier
connected to the source end of the relation.source(const engine: Classengine)
.BinaryRelationBuilder.target(classifier: Classifier<any, any>): BinaryRelationBuilderSets the
Classifier
connected to the target end of the relation.target(const car: Classcar)
.BinaryRelationBuilder.build(): BinaryRelationBuilds an instance of
BinaryRelation
with the parameters passed
to the builder. Both the source and the target classifiers are required
before `build()` is evoked. **WARNING:** the ordering in which methods
are evoked may affect the resulting object. When no methods are evoked,
the created relation has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`build();
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`console.log()`** static method outputs a message to the console.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const hasEngine: BinaryRelationhasEngine.BinaryRelation.isPartWholeRelation(): booleanChecks whether the relation is a parthood (part-whole) relation between
classes, i.e., whether its target end is decorated with an aggregation
kind (shared or composite) while its source end is not.isPartWholeRelation()); // true
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`console.log()`** static method outputs a message to the console.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const hasEngine: BinaryRelationhasEngine.BinaryRelation.targetEnd: PropertyThe relation end at the target (second) position.targetEnd.Property.isComposite(): booleanChecks whether this property is a relation end decorated with composite
aggregation.isComposite()); // true
Now you try it
Employment is a relator connecting Person and Company. Add the two
«mediation» relations that bind it — one to each class — then check the
console.
Show the solution
Key takeaways
- A binary relation connects a source and a target, both required.
- Build it from a package with
binaryRelationBuilder()and a stereotype shortcut that also applies OntoUML's default meta-properties. - A relation's ends are properties — cardinality, ordering, and read-only
live on
sourceEnd/targetEnd, reachable viagetOppositeEnd(). - Parthood uses aggregation on the whole end:
.composition()(exclusive) or.aggregation()(shared).
Next: n-ary relations →, for connections among three or more classes.