Skip to main content
Version: Next

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.

Theory: properties, attributes, and relation ends

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 Project
An 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.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
} from 'ontouml-js';
const const project: Projectproject = new new Project(): Project
An 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.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilder
Creates a builder for a new Package in this project.
packageBuilder
().PackageBuilder.root(): PackageBuilder
Sets the package as the root package of its project, i.e., the package that contains the entire model.
@returnsthis builder, for method chaining.
root
().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Library').PackageBuilder.build(): Package
Builds 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: []`
@throwsan error if the builder has already been used.
build
();
// Datatypes are ordinary classes stereotyped «datatype». const const string: Classstring = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.datatype(): ClassBuilder
Sets 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`
@returnsthis builder, for method chaining.
datatype
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('String').ClassBuilder.build(): Class
Builds 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,`
@throwsan error if the builder has already been used.
build
();
const const date: Classdate = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.datatype(): ClassBuilder
Sets 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`
@returnsthis builder, for method chaining.
datatype
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Date').ClassBuilder.build(): Class
Builds 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,`
@throwsan error if the builder has already been used.
build
();
const const person: Classperson = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.kind(): ClassBuilder
Sets 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`
@returnsthis builder, for method chaining.
kind
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Person').ClassBuilder.build(): Class
Builds 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,`
@throwsan error if the builder has already been used.
build
();
const const name: Propertyname = const person: Classperson.Class.propertyBuilder(): PropertyBuilder
Creates a builder for a Property owned by this class.
propertyBuilder
().NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('name').PropertyBuilder.type(c: Class): PropertyBuilder
Sets the Class that types the property, i.e., the class whose instances are the possible values of the property.
@returnsthis builder, for method chaining.
type
(const string: Classstring).PropertyBuilder.one(): PropertyBuilder
Sets the cardinality of the property to `1`.
@returnsthis builder, for method chaining.
one
().PropertyBuilder.build(): Property
Builds 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..*"`
@throwsan error if the builder has already been used.
build
();
const const birthDate: PropertybirthDate = const person: Classperson .Class.propertyBuilder(): PropertyBuilder
Creates a builder for a Property owned by this class.
propertyBuilder
()
.NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('birthDate')
.PropertyBuilder.type(c: Class): PropertyBuilder
Sets the Class that types the property, i.e., the class whose instances are the possible values of the property.
@returnsthis builder, for method chaining.
type
(const date: Classdate)
.PropertyBuilder.optional(): PropertyBuilder
Sets the cardinality of the property to `0..1`.
@returnsthis builder, for method chaining.
optional
()
.PropertyBuilder.build(): Property
Builds 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..*"`
@throwsan error if the builder has already been used.
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[]): void
The **`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: number
Gets 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 callCardinalityMeaning
.one()1exactly one (mandatory)
.optional()0..1at most one
.some()1..*at least one
.many()0..*any number (the default)
.cardinality('2..5')2..5a custom interval
import { class Project
An 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.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
} from 'ontouml-js';
const const project: Projectproject = new new Project(): Project
An 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.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilder
Creates a builder for a new Package in this project.
packageBuilder
().PackageBuilder.root(): PackageBuilder
Sets the package as the root package of its project, i.e., the package that contains the entire model.
@returnsthis builder, for method chaining.
root
().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Library').PackageBuilder.build(): Package
Builds 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: []`
@throwsan error if the builder has already been used.
build
();
const const string: Classstring = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.datatype(): ClassBuilder
Sets 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`
@returnsthis builder, for method chaining.
datatype
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('String').ClassBuilder.build(): Class
Builds 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,`
@throwsan error if the builder has already been used.
build
();
const const book: Classbook = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.kind(): ClassBuilder
Sets 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`
@returnsthis builder, for method chaining.
kind
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Book').ClassBuilder.build(): Class
Builds 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,`
@throwsan error if the builder has already been used.
build
();
const const title: Propertytitle = const book: Classbook.Class.propertyBuilder(): PropertyBuilder
Creates a builder for a Property owned by this class.
propertyBuilder
().NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('title').PropertyBuilder.type(c: Class): PropertyBuilder
Sets the Class that types the property, i.e., the class whose instances are the possible values of the property.
@returnsthis builder, for method chaining.
type
(const string: Classstring).PropertyBuilder.one(): PropertyBuilder
Sets the cardinality of the property to `1`.
@returnsthis builder, for method chaining.
one
().PropertyBuilder.build(): Property
Builds 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..*"`
@throwsan error if the builder has already been used.
build
();
const const authors: Propertyauthors = const book: Classbook .Class.propertyBuilder(): PropertyBuilder
Creates a builder for a Property owned by this class.
propertyBuilder
()
.NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('authors')
.PropertyBuilder.type(c: Class): PropertyBuilder
Sets the Class that types the property, i.e., the class whose instances are the possible values of the property.
@returnsthis builder, for method chaining.
type
(const string: Classstring)
.PropertyBuilder.some(): PropertyBuilder
Sets the cardinality of the property to `1..*`.
@returnsthis builder, for method chaining.
some
()
.PropertyBuilder.build(): Property
Builds 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..*"`
@throwsan error if the builder has already been used.
build
();
// The built property carries a Cardinality object with query and mutation // helpers. var console: Consoleconsole.Console.log(...data: any[]): void
The **`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: Cardinality
The multiplicity of this property. Defaults to `0..*`.
cardinality
.Cardinality.isMandatory(): boolean
Checks 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: Cardinality
The multiplicity of this property. Defaults to `0..*`.
cardinality
.Cardinality.setAsOneToMany(): void
Sets 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 Project
An 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.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
} from 'ontouml-js';
const const project: Projectproject = new new Project(): Project
An 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.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilder
Creates a builder for a new Package in this project.
packageBuilder
().PackageBuilder.root(): PackageBuilder
Sets the package as the root package of its project, i.e., the package that contains the entire model.
@returnsthis builder, for method chaining.
root
().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Library').PackageBuilder.build(): Package
Builds 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: []`
@throwsan error if the builder has already been used.
build
();
const const string: Classstring = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.datatype(): ClassBuilder
Sets 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`
@returnsthis builder, for method chaining.
datatype
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('String').ClassBuilder.build(): Class
Builds 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,`
@throwsan error if the builder has already been used.
build
();
const const date: Classdate = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.datatype(): ClassBuilder
Sets 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`
@returnsthis builder, for method chaining.
datatype
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Date').ClassBuilder.build(): Class
Builds 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,`
@throwsan error if the builder has already been used.
build
();
const const book: Classbook = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.kind(): ClassBuilder
Sets 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`
@returnsthis builder, for method chaining.
kind
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Book').ClassBuilder.build(): Class
Builds 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,`
@throwsan error if the builder has already been used.
build
();
const book: Classbook .Class.propertyBuilder(): PropertyBuilder
Creates a builder for a Property owned by this class.
propertyBuilder
()
.NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('editionHistory')
.PropertyBuilder.type(c: Class): PropertyBuilder
Sets the Class that types the property, i.e., the class whose instances are the possible values of the property.
@returnsthis builder, for method chaining.
type
(const string: Classstring)
.PropertyBuilder.many(): PropertyBuilder
Sets the cardinality of the property to `0..*`.
@returnsthis builder, for method chaining.
many
()
.PropertyBuilder.ordered(): PropertyBuilder
Sets the property as ordered, i.e., as a property whose values are arranged in a meaningful sequence.
@returnsthis builder, for method chaining.
ordered
()
.PropertyBuilder.build(): Property
Builds 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..*"`
@throwsan error if the builder has already been used.
build
();
const book: Classbook .Class.propertyBuilder(): PropertyBuilder
Creates a builder for a Property owned by this class.
propertyBuilder
()
.NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('firstPublished')
.PropertyBuilder.type(c: Class): PropertyBuilder
Sets the Class that types the property, i.e., the class whose instances are the possible values of the property.
@returnsthis builder, for method chaining.
type
(const date: Classdate)
.PropertyBuilder.one(): PropertyBuilder
Sets the cardinality of the property to `1`.
@returnsthis builder, for method chaining.
one
()
.PropertyBuilder.readOnly(): PropertyBuilder
Sets the property as read-only, i.e., as a property whose values cannot change once assigned.
@returnsthis builder, for method chaining.
readOnly
()
.PropertyBuilder.build(): Property
Builds 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..*"`
@throwsan error if the builder has already been used.
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 Project
An 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.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
} from 'ontouml-js';
const const project: Projectproject = new new Project(): Project
An 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.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilder
Creates a builder for a new Package in this project.
packageBuilder
().PackageBuilder.root(): PackageBuilder
Sets the package as the root package of its project, i.e., the package that contains the entire model.
@returnsthis builder, for method chaining.
root
().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Library').PackageBuilder.build(): Package
Builds 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: []`
@throwsan error if the builder has already been used.
build
();
const const bookStatus: ClassbookStatus = const model: Packagemodel .Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
()
.ClassBuilder.enumeration(): ClassBuilder
Sets 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`
@returnsthis builder, for method chaining.
enumeration
()
.NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('BookStatus')
.ClassBuilder.build(): Class
Builds 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,`
@throwsan error if the builder has already been used.
build
();
const bookStatus: ClassbookStatus.Class.literalBuilder(): LiteralBuilder
Creates a builder for a Literal owned by this class.
@throwsan error if the class is not decorated with «enumeration».
literalBuilder
().NamedElementBuilder<LiteralBuilder>.name(value: string, language?: string): LiteralBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Available').LiteralBuilder.build(): Literal
Builds 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",`
@throwsan error if the builder has already been used.
build
();
const bookStatus: ClassbookStatus.Class.literalBuilder(): LiteralBuilder
Creates a builder for a Literal owned by this class.
@throwsan error if the class is not decorated with «enumeration».
literalBuilder
().NamedElementBuilder<LiteralBuilder>.name(value: string, language?: string): LiteralBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('OnLoan').LiteralBuilder.build(): Literal
Builds 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",`
@throwsan error if the builder has already been used.
build
();
const bookStatus: ClassbookStatus.Class.literalBuilder(): LiteralBuilder
Creates a builder for a Literal owned by this class.
@throwsan error if the class is not decorated with «enumeration».
literalBuilder
().NamedElementBuilder<LiteralBuilder>.name(value: string, language?: string): LiteralBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Lost').LiteralBuilder.build(): Literal
Builds 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",`
@throwsan error if the builder has already been used.
build
();
const const book: Classbook = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.kind(): ClassBuilder
Sets 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`
@returnsthis builder, for method chaining.
kind
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Book').ClassBuilder.build(): Class
Builds 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,`
@throwsan error if the builder has already been used.
build
();
const book: Classbook.Class.propertyBuilder(): PropertyBuilder
Creates a builder for a Property owned by this class.
propertyBuilder
().NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('status').PropertyBuilder.type(c: Class): PropertyBuilder
Sets the Class that types the property, i.e., the class whose instances are the possible values of the property.
@returnsthis builder, for method chaining.
type
(const bookStatus: ClassbookStatus).PropertyBuilder.one(): PropertyBuilder
Sets the cardinality of the property to `1`.
@returnsthis builder, for method chaining.
one
().PropertyBuilder.build(): Property
Builds 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..*"`
@throwsan error if the builder has already been used.
build
();
var console: Consoleconsole.Console.log(...data: any[]): void
The **`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.
@paramcallbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.@paramthisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
map
(l: Literall => l: Literall.NamedElement.getNameOrId(language?: string): string
Returns the name of this element in the given language, falling back to its id when no suitable name is available.
@paramlanguage - language tag of the desired name (e.g., `"en"`); when omitted, the name is selected according to LanguageString.languagePreference.
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 among p's values.
  • .redefines(p) — this attribute overrides the inherited p (a narrower type or tighter cardinality).
import { class Project
An 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.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
} from 'ontouml-js';
const const project: Projectproject = new new Project(): Project
An 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.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilder
Creates a builder for a new Package in this project.
packageBuilder
().PackageBuilder.root(): PackageBuilder
Sets the package as the root package of its project, i.e., the package that contains the entire model.
@returnsthis builder, for method chaining.
root
().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Library').PackageBuilder.build(): Package
Builds 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: []`
@throwsan error if the builder has already been used.
build
();
const const string: Classstring = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.datatype(): ClassBuilder
Sets 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`
@returnsthis builder, for method chaining.
datatype
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('String').ClassBuilder.build(): Class
Builds 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,`
@throwsan error if the builder has already been used.
build
();
const const person: Classperson = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.kind(): ClassBuilder
Sets 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`
@returnsthis builder, for method chaining.
kind
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Person').ClassBuilder.build(): Class
Builds 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,`
@throwsan error if the builder has already been used.
build
();
const const contacts: Propertycontacts = const person: Classperson .Class.propertyBuilder(): PropertyBuilder
Creates a builder for a Property owned by this class.
propertyBuilder
()
.NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('contacts')
.PropertyBuilder.type(c: Class): PropertyBuilder
Sets the Class that types the property, i.e., the class whose instances are the possible values of the property.
@returnsthis builder, for method chaining.
type
(const string: Classstring)
.PropertyBuilder.many(): PropertyBuilder
Sets the cardinality of the property to `0..*`.
@returnsthis builder, for method chaining.
many
()
.PropertyBuilder.build(): Property
Builds 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..*"`
@throwsan error if the builder has already been used.
build
();
const const employee: Classemployee = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.role(): ClassBuilder
Sets 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`).
@returnsthis builder, for method chaining.
role
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Employee').ClassBuilder.build(): Class
Builds 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,`
@throwsan error if the builder has already been used.
build
();
const person: Classperson.Classifier<Class, ClassStereotype>.addChild(child: Class): Generalization
Creates a Generalization in which this classifier is the general and the given classifier is the specific.
@paramchild - the classifier to be set as the specific.@returnsthe newly created generalization.
addChild
(const employee: Classemployee);
// An employee's work email is one of their contacts. const employee: Classemployee .Class.propertyBuilder(): PropertyBuilder
Creates a builder for a Property owned by this class.
propertyBuilder
()
.NamedElementBuilder<PropertyBuilder>.name(value: string, language?: string): PropertyBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('workEmail')
.PropertyBuilder.type(c: Class): PropertyBuilder
Sets the Class that types the property, i.e., the class whose instances are the possible values of the property.
@returnsthis builder, for method chaining.
type
(const string: Classstring)
.PropertyBuilder.one(): PropertyBuilder
Sets the cardinality of the property to `1`.
@returnsthis builder, for method chaining.
one
()
.PropertyBuilder.subsets(p: Property): PropertyBuilder
Adds a Property subsetted by this property, i.e., a property whose values are a superset of the values of this property.
@returnsthis builder, for method chaining.
subsets
(const contacts: Propertycontacts)
.PropertyBuilder.build(): Property
Builds 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..*"`
@throwsan error if the builder has already been used.
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.

Loading playground…
Show the solution
Loading playground…

Key takeaways​

  • An attribute is a Property owned by a class; build it from class.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 with literalBuilder().
  • .subsets() and .redefines() relate an attribute to an inherited one.

Next: binary relations →, where properties take on their other role — as relation ends.