All Downloads are FREE. Search and download functionalities are using the official Maven repository.

reference.language.category_inheritance.html Maven / Gradle / Ivy




    
    Categories
    
    

    
    

    
    

    
    
    
    

    


Category inheritance

Prompto supports category inheritance, where a category extends another category, and therefore inherits its attributes and methods.
In the E dialect, this is done by using the name of the category being extended in place of the category keyword.
In the O dialect, this is done by appending to the category definition the extend keyword followed the name of the category being extended.
In the M dialect, this is done by inserting the name of the category being extended before the list of attributes.

A category extending another category is often referred to as a derived category.

An object of a derived category can be used anywhere an object of the original category is expected.

In the below example, the printPerson method expects a Person object, and will accept any object inheriting from Person:

Multiple inheritance

Prompto supports multiple inheritance, where a category extends not just one category, but many.
This is done by using a list of category names rather than just one:

In the above example, a SmartPhone is a Product, a Computer and a Phone.

It inherits attributes and methods from those 3 categories i.e. brand, operatingSystem and supportedNetwork:

Multiple inheritance of attributes in Prompto does not suffer from the deadly diamond problem. This is thanks to its unique reified attributes feature, where attributes are semantic types defined outside categories.

In the above example, since attributes are defined globally, the brand attribute is the same in all 4 categories, and has the same meaning. From there, the SmartPhone category only inherits the brand attribute once (as opposed to multiple times in most OOP languages which support multiple inheritance).

Multiple inheritance of methods in Prompto follows the inheritance sequence. This is described in the next section.





© 2015 - 2025 Weber Informatics LLC | Privacy Policy