
reference.language.category_abstract.html Maven / Gradle / Ivy
Methods
Abstract categories
Like global methods, category methods can be declared abstract. A category which contains 1 or more abstract method is said to be an abstract category.
The category is abstract in the sense that you cannot create an object of that category. The reason is that if you could, Prompto would irremediably fail when
your code tries to call an abstract method for that instance.
Instead, the abstract method(s) must be defined in categories derived from it.
This is done simply by providing inside the derived category definition a concrete version of the abstract method defined in the parent category.
In the below example, we:
- define an 'Animal' category with an abstract 'speak' method
- define an 'Dog' category, derived from 'Animal', which implements the 'speak' method
- define an 'Cat' category, derived from 'Animal', which implements the 'speak' method
- call the 'speak' method for an instance of each of them
© 2015 - 2025 Weber Informatics LLC | Privacy Policy