Get in touch
Get in touch

Subclassing and inheritance

Sometimes the Concept type you want to give your data shares a common pattern with other types. In Data Graphs it is possible to make types that share some common parent type. This is sometimes referred to as classes being a subclass of another class.

This allows you to share common properties from the parent class and to facet on the child and parent class simultaneously.

For example, you might have a Vehicle Concept type that has properties for name and manufacturer. You could then define more specific Concept types for planes and motor vehicles. These might have their own set of specific properties – wing length for planes or transmission type for motor vehicles – but they will inherit the properties of the Vehicle Concept type as well.

In addition, when you search for anything made by a manufacturer, your results will show any type of vehicle – plane or motor vehicle.

Planning your Concept type hierarchy

If you have already designed your model, it is useful to define Concept types related by subclassing and inheritance in Data Graphs from the top down. Start with the parent type and work down to define more specific Concept types. When it comes to creating a new type it is as simple as selecting from the existing parent types in the drop down list. By defining your parent types first they will be available to select when it comes to defining more specific Concept types.

Creating subclasses

You create a subclass when creating a Concept type schema in a Dataset.

You can do this in one of two ways:

  1. Using the domain modelling tool you can connect a child class to a parent class visually to create a subclass relationship

  1. After naming your Concept, you have the option of choosing a Parent Type for the Concept you are defining.

By selecting the Include parent properties option, your new subclass will inherit (re-use) the properties from the parent class. This is most likely what you will need to.

Managing classes

The Class Explorer screen allows you to see a visual representation of your current type hierarchy. This view is accessible by selecting Class Explorer button in the domain modelling tool. Within this screen you can remove a type that you no longer require or have created incorrectly in your type hierarchy.

Transitive class inference

When you create a subclass type, Concept relationships become class-structure aware, with transitive inference. When a Concept property defines a relationship to another Concept type/class, Data Graphs allows you to select Concept instances of that type and all its subclasses. 

For example, if you create a class FootballTeam that is a sub-class of Organization, and you then create a property on another Concept of type Organization, transitive inference means that football teams can be assigned to that property as well as organizations. Search facets and API queries also obey the semantics of transitive inference across a class hierarchy.