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 or a sub-type when creating a Concept type schema in a Dataset. After naming your Concept, you have the option of choosing a Parent Type for the Concept you are defining.

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

Managing types

The Manage Types screen allows you to see a visual representation of your current type hierarchy. This view is accessible by selecting Manage Types in the main account menu in the navbar. 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.