🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators allSubClasses
This page was created by Alexandra on 2017-08-13. Last edited by Wikiadmin on 2026-07-29.

You can use allSubClasses in OCL when you need the complete inheritance descendants of a class, for example when inspecting or validating the types defined in your model.

Syntax

TypeName.allSubClasses

What it returns

allSubClasses is a meta-model operation. It returns a collection containing the names of every subclass of the specified class:

  • Direct subclasses — classes that inherit from the specified class.
  • Indirect subclasses — classes that inherit from one of those subclasses.

The result describes the model's type hierarchy. It does not return objects created from those classes. To work with existing objects, use allInstances.

Example

Assume this inheritance hierarchy:

Department
├── ClinicalDepartment
│   └── EmergencyDepartment
└── AdministrativeDepartment

Use the operator on Department:

Department.allSubClasses

The result contains:

['ClinicalDepartment', 'EmergencyDepartment', 'AdministrativeDepartment']

ClinicalDepartment and AdministrativeDepartment are direct subclasses of Department. EmergencyDepartment is included because it is an indirect subclass through ClinicalDepartment.

When to use it

Use allSubClasses when an expression needs to inspect the complete set of specialized types below a class. For example, use Department.allSubClasses to identify every department type derived from the common Department type.

Do not use it to test whether an object belongs to a type hierarchy. For an object-level type test, use oclIsKindOf.

Related inheritance operations

Operation Returns Example
allSubClasses All direct and indirect subclasses of a class Department.allSubClasses
superTypes Direct parent types only Mango.superTypes
allSuperTypes All direct and indirect parent types Mango.allSuperTypes

See also