Class inheritance
Copyright 2008-2012 ManyDesigns srl. All rights reserved.
Contents
Purpose
Inheritance is a parent-child relation used to expresses the concept of generalization/specialization: a parent class is a generalization of a child class; a child class is a specialization of a parent class. For example a parent class could be Animal, while some child classes could be Mammal, Bird and Reptile.
Parent classes are also called super-classes. Child classes are also called sub-classes or derived classes. A class with no parent is also called a base class.
Inheritance can be applied recursively. You can have a child class of a child class. Collectively, all the classes and their inheritance relations together make a hierarchy (or taxonomy according to another terminology).
Inheritance is a common concept in object-oriented design. If class B is a child of class A, then B can be used wherever A can be used. In fact, B "inherits" all the behaviours of A. More formally, B inherits from A:
- the attributes
- the relationships
- the workflow (if present) including states and transitions
- the operations
- the permissions
Class B can also define elements of its own, which extend those inherited from A. Generally this inheritance/extension works in straightforward way. Here we will only discuss the exceptions and special cases.
Workflow
In the chapter on workflows, we discussed that a class can have at most one workflow attribute. This is true regardless of whether the attribute belongs to the class directly or to one of its parent/ancestor classes.
In other words, if a class has a workflow attribute, none of its child classes can have another workflow attribute.
Permissions
If you define class B as a child of class A and visit B's permissions page, you will find that any actors and permissions defined for A are present also in B. The only unusual thing is that those inherited actors/permission are grayed out and cannot be changed.
More formally, permissions and inheritance abide to the following rules:
- Any class, whether parent or child, can define its own actors.
- Child classes inherit their parent's actors in "read-only".
- The permissions on an attribute can only be set on the class that owns the attribute. Any child class sees those permissions in "read-only".
- A class can define the permissions on its own attributes in terms of any actor, whether its own or inherited.
- The create and delete permissions must be defined on the base class.
Previous: BLOBs
Next: Custom operations