Attributes
A class describes its instances through attributes — the intrinsic, "owned"
pieces of structure every instance carries: a person's name, a book's
isbn, an account's balance.
In OntoUML (as in UML) the underlying concept is a property: a named, typed, multiplicity-bearing feature of a classifier. A property plays one of two roles depending on what contains it:
- contained in a class, it is an attribute — the subject of this chapter;
- contained in a relation, it is a relation end — covered under binary and n-ary relations.
Same object, same builder, two roles. That's why cardinality, ordering, and read-only status show up in both places.
Building an attribute
Attributes are created from the class that owns them, via
classBuilder-style factories — here class.propertyBuilder(). An attribute
needs a type, and in OntoUML a type is itself a class: usually one
stereotyped «datatype» (or «enumeration»). There are no built-in
primitives, so you declare the datatypes your model uses and point attributes
at them.
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('Library').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();
// Datatypes are ordinary classes stereotyped «datatype».
const const string: Classstring = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.datatype(): ClassBuilderSets the stereotype of the class to «datatype», which decorates classes
whose instances are values of a (possibly structured) value space (e.g.,
`Date`, `Address`). Also applies the following defaults:
- `restrictedTo = [ "abstract" ]`
- `order = 1`datatype().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('String').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 date: Classdate = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.datatype(): ClassBuilderSets the stereotype of the class to «datatype», which decorates classes
whose instances are values of a (possibly structured) value space (e.g.,
`Date`, `Address`). Also applies the following defaults:
- `restrictedTo = [ "abstract" ]`
- `order = 1`datatype().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Date').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 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 name: Propertyname = const person: Classperson.Class.propertyBuilder(): PropertyBuilderCreates a builder for a
Property
owned by this class.propertyBuilder().NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilderAdds a name to the element in the given language.name('name').PropertyBuilder.type(c: Class): PropertyBuilderSets the
Class
that types the property, i.e., the class whose
instances are the possible values of the property.type(const string: Classstring).PropertyBuilder.one(): PropertyBuilderSets the cardinality of the property to `1`.one().PropertyBuilder.build(): PropertyBuilds an instance of
Property
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
property has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isDerived: false,`
- `isReadOnly: false,`
- `isOrdered: false,`
- `cardinality: "0..*"`build();
const const birthDate: PropertybirthDate = const person: Classperson
.Class.propertyBuilder(): PropertyBuilderCreates a builder for a
Property
owned by this class.propertyBuilder()
.NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilderAdds a name to the element in the given language.name('birthDate')
.PropertyBuilder.type(c: Class): PropertyBuilderSets the
Class
that types the property, i.e., the class whose
instances are the possible values of the property.type(const date: Classdate)
.PropertyBuilder.optional(): PropertyBuilderSets the cardinality of the property to `0..1`.optional()
.PropertyBuilder.build(): PropertyBuilds an instance of
Property
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
property has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isDerived: false,`
- `isReadOnly: false,`
- `isOrdered: false,`
- `cardinality: "0..*"`build();
const const attributes: Property[]attributes = const person: Classperson.Class.attributes: Property[]The attributes defined in this class, excluding inherited ones.attributes;
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 attributes: Property[]attributes.Array<Property>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.length); // 2
Hover attributes above: Class.attributes returns the Property[] owned by
the class. person.hasAttributes() is the quick boolean.
Cardinality
Every attribute has a cardinality — how many values an instance may hold.
The default is 0..*. The builder gives you shortcuts for the common cases,
plus cardinality(...) for an explicit bound:
| Builder call | Cardinality | Meaning |
|---|---|---|
.one() | 1 | exactly one (mandatory) |
.optional() | 0..1 | at most one |
.some() | 1..* | at least one |
.many() | 0..* | any number (the default) |
.cardinality('2..5') | 2..5 | a custom interval |
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('Library').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 string: Classstring = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.datatype(): ClassBuilderSets the stereotype of the class to «datatype», which decorates classes
whose instances are values of a (possibly structured) value space (e.g.,
`Date`, `Address`). Also applies the following defaults:
- `restrictedTo = [ "abstract" ]`
- `order = 1`datatype().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('String').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 book: Classbook = 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('Book').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 title: Propertytitle = const book: Classbook.Class.propertyBuilder(): PropertyBuilderCreates a builder for a
Property
owned by this class.propertyBuilder().NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilderAdds a name to the element in the given language.name('title').PropertyBuilder.type(c: Class): PropertyBuilderSets the
Class
that types the property, i.e., the class whose
instances are the possible values of the property.type(const string: Classstring).PropertyBuilder.one(): PropertyBuilderSets the cardinality of the property to `1`.one().PropertyBuilder.build(): PropertyBuilds an instance of
Property
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
property has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isDerived: false,`
- `isReadOnly: false,`
- `isOrdered: false,`
- `cardinality: "0..*"`build();
const const authors: Propertyauthors = const book: Classbook
.Class.propertyBuilder(): PropertyBuilderCreates a builder for a
Property
owned by this class.propertyBuilder()
.NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilderAdds a name to the element in the given language.name('authors')
.PropertyBuilder.type(c: Class): PropertyBuilderSets the
Class
that types the property, i.e., the class whose
instances are the possible values of the property.type(const string: Classstring)
.PropertyBuilder.some(): PropertyBuilderSets the cardinality of the property to `1..*`.some()
.PropertyBuilder.build(): PropertyBuilds an instance of
Property
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
property has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isDerived: false,`
- `isReadOnly: false,`
- `isOrdered: false,`
- `cardinality: "0..*"`build();
// The built property carries a Cardinality object with query and mutation
// helpers.
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 title: Propertytitle.Property.cardinality: CardinalityThe multiplicity of this property. Defaults to `0..*`.cardinality.Cardinality.isMandatory(): booleanChecks whether the property is mandatory, i.e., whether the lower bound
of the cardinality is greater than zero.isMandatory()); // true
const authors: Propertyauthors.Property.cardinality: CardinalityThe multiplicity of this property. Defaults to `0..*`.cardinality.Cardinality.setAsOneToMany(): voidSets the cardinality to `1..*`.setAsOneToMany();
Ordering and read-only
Two further meta-properties apply to attributes:
- Ordered (
.ordered()) — the values form a meaningful sequence rather than a set. Think of the ordered stops on a route. - Read-only (
.readOnly()) — once assigned, a value cannot change.
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('Library').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 string: Classstring = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.datatype(): ClassBuilderSets the stereotype of the class to «datatype», which decorates classes
whose instances are values of a (possibly structured) value space (e.g.,
`Date`, `Address`). Also applies the following defaults:
- `restrictedTo = [ "abstract" ]`
- `order = 1`datatype().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('String').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 date: Classdate = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.datatype(): ClassBuilderSets the stereotype of the class to «datatype», which decorates classes
whose instances are values of a (possibly structured) value space (e.g.,
`Date`, `Address`). Also applies the following defaults:
- `restrictedTo = [ "abstract" ]`
- `order = 1`datatype().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Date').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 book: Classbook = 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('Book').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 book: Classbook
.Class.propertyBuilder(): PropertyBuilderCreates a builder for a
Property
owned by this class.propertyBuilder()
.NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilderAdds a name to the element in the given language.name('editionHistory')
.PropertyBuilder.type(c: Class): PropertyBuilderSets the
Class
that types the property, i.e., the class whose
instances are the possible values of the property.type(const string: Classstring)
.PropertyBuilder.many(): PropertyBuilderSets the cardinality of the property to `0..*`.many()
.PropertyBuilder.ordered(): PropertyBuilderSets the property as ordered, i.e., as a property whose values are
arranged in a meaningful sequence.ordered()
.PropertyBuilder.build(): PropertyBuilds an instance of
Property
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
property has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isDerived: false,`
- `isReadOnly: false,`
- `isOrdered: false,`
- `cardinality: "0..*"`build();
const book: Classbook
.Class.propertyBuilder(): PropertyBuilderCreates a builder for a
Property
owned by this class.propertyBuilder()
.NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilderAdds a name to the element in the given language.name('firstPublished')
.PropertyBuilder.type(c: Class): PropertyBuilderSets the
Class
that types the property, i.e., the class whose
instances are the possible values of the property.type(const date: Classdate)
.PropertyBuilder.one(): PropertyBuilderSets the cardinality of the property to `1`.one()
.PropertyBuilder.readOnly(): PropertyBuilderSets the property as read-only, i.e., as a property whose values cannot
change once assigned.readOnly()
.PropertyBuilder.build(): PropertyBuilds an instance of
Property
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
property has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isDerived: false,`
- `isReadOnly: false,`
- `isOrdered: false,`
- `cardinality: "0..*"`build();
Enumerations and literals
An «enumeration» is a datatype whose value space is a fixed set of named
literals — the OntoUML counterpart of a TypeScript string-union type.
Literals are built from the enumeration class with literalBuilder().
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('Library').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 bookStatus: ClassbookStatus = const model: Packagemodel
.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder()
.ClassBuilder.enumeration(): ClassBuilderSets the stereotype of the class to «enumeration», which decorates
classes whose instances form a fixed set of literals (e.g., `Color` with
the literals `Red`, `Green`, and `Blue`). Also applies the following
defaults:
- `restrictedTo = [ "abstract" ]`
- `order = 1`enumeration()
.NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('BookStatus')
.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 bookStatus: ClassbookStatus.Class.literalBuilder(): LiteralBuilderCreates a builder for a
Literal
owned by this class.literalBuilder().NamedElementBuilder<LiteralBuilder>.name(value: string, language?: string): LiteralBuilderAdds a name to the element in the given language.name('Available').LiteralBuilder.build(): LiteralBuilds an instance of
Literal
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
literal has the following defaults:
- `id: "randomly-generated-id",`build();
const bookStatus: ClassbookStatus.Class.literalBuilder(): LiteralBuilderCreates a builder for a
Literal
owned by this class.literalBuilder().NamedElementBuilder<LiteralBuilder>.name(value: string, language?: string): LiteralBuilderAdds a name to the element in the given language.name('OnLoan').LiteralBuilder.build(): LiteralBuilds an instance of
Literal
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
literal has the following defaults:
- `id: "randomly-generated-id",`build();
const bookStatus: ClassbookStatus.Class.literalBuilder(): LiteralBuilderCreates a builder for a
Literal
owned by this class.literalBuilder().NamedElementBuilder<LiteralBuilder>.name(value: string, language?: string): LiteralBuilderAdds a name to the element in the given language.name('Lost').LiteralBuilder.build(): LiteralBuilds an instance of
Literal
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
literal has the following defaults:
- `id: "randomly-generated-id",`build();
const const book: Classbook = 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('Book').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 book: Classbook.Class.propertyBuilder(): PropertyBuilderCreates a builder for a
Property
owned by this class.propertyBuilder().NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilderAdds a name to the element in the given language.name('status').PropertyBuilder.type(c: Class): PropertyBuilderSets the
Class
that types the property, i.e., the class whose
instances are the possible values of the property.type(const bookStatus: ClassbookStatus).PropertyBuilder.one(): PropertyBuilderSets the cardinality of the property to `1`.one().PropertyBuilder.build(): PropertyBuilds an instance of
Property
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
property has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isDerived: false,`
- `isReadOnly: false,`
- `isOrdered: false,`
- `cardinality: "0..*"`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 bookStatus: ClassbookStatus.Class.literals: Literal[]The literals defined in this class, excluding inherited ones.
Sets the literals defined in this class, detaching any previously owned
literals.literals.Array<Literal>.map<string>(callbackfn: (value: Literal, index: number, array: Literal[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.map(l: Literall => l: Literall.NamedElement.getNameOrId(language?: string): stringReturns the name of this element in the given language, falling back to
its
id
when no suitable name is available.getNameOrId())); // Available, OnLoan, Lost
Subsetting and redefining
When a subtype refines an inherited attribute, two relationships let you say
how. Both take another Property and are set on the builder:
.subsets(p)— this attribute's values are always amongp's values..redefines(p)— this attribute overrides the inheritedp(a narrower type or tighter cardinality).
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('Library').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 string: Classstring = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.datatype(): ClassBuilderSets the stereotype of the class to «datatype», which decorates classes
whose instances are values of a (possibly structured) value space (e.g.,
`Date`, `Address`). Also applies the following defaults:
- `restrictedTo = [ "abstract" ]`
- `order = 1`datatype().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('String').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 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 contacts: Propertycontacts = const person: Classperson
.Class.propertyBuilder(): PropertyBuilderCreates a builder for a
Property
owned by this class.propertyBuilder()
.NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilderAdds a name to the element in the given language.name('contacts')
.PropertyBuilder.type(c: Class): PropertyBuilderSets the
Class
that types the property, i.e., the class whose
instances are the possible values of the property.type(const string: Classstring)
.PropertyBuilder.many(): PropertyBuilderSets the cardinality of the property to `0..*`.many()
.PropertyBuilder.build(): PropertyBuilds an instance of
Property
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
property has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isDerived: false,`
- `isReadOnly: false,`
- `isOrdered: false,`
- `cardinality: "0..*"`build();
const const employee: Classemployee = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.role(): ClassBuilderSets the stereotype of the class to «role», which decorates anti-rigid
classes whose instances are contingently classified by virtue of a
relational condition (e.g., `Student`, `Employee`).role().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Employee').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 person: Classperson.Classifier<Class, ClassStereotype>.addChild(child: Class): GeneralizationCreates a
Generalization
in which this classifier is the
general and the given classifier is the specific.addChild(const employee: Classemployee);
// An employee's work email is one of their contacts.
const employee: Classemployee
.Class.propertyBuilder(): PropertyBuilderCreates a builder for a
Property
owned by this class.propertyBuilder()
.NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilderAdds a name to the element in the given language.name('workEmail')
.PropertyBuilder.type(c: Class): PropertyBuilderSets the
Class
that types the property, i.e., the class whose
instances are the possible values of the property.type(const string: Classstring)
.PropertyBuilder.one(): PropertyBuilderSets the cardinality of the property to `1`.one()
.PropertyBuilder.subsets(p: Property): PropertyBuilderAdds a
Property
subsetted by this property, i.e., a property
whose values are a superset of the values of this property.subsets(const contacts: Propertycontacts)
.PropertyBuilder.build(): PropertyBuilds an instance of
Property
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
property has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isDerived: false,`
- `isReadOnly: false,`
- `isOrdered: false,`
- `cardinality: "0..*"`build();
Now you try it
Loan is a relator with no structure yet. Give it a loanedOn attribute of
type Date, mandatory and read-only, then open the console to see it in
the serialized JSON.
Show the solution
Key takeaways
- An attribute is a
Propertyowned by a class; build it fromclass.propertyBuilder(). - Attributes are typed by classes — usually
«datatype»or«enumeration»classes you declare yourself. - Cardinality shortcuts:
.one(),.optional(),.some(),.many(), or.cardinality('a..b');.ordered()and.readOnly()add meta-properties. - Enumerations hold
«literal»values built withliteralBuilder(). .subsets()and.redefines()relate an attribute to an inherited one.
Next: binary relations →, where properties take on their other role — as relation ends.