VDM-10 Language Manual
VDM-10 Language Manual
VDM-10 Language Manual
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>VDM</strong>-<strong>10</strong> <strong>Language</strong> <strong>Manual</strong><br />
14.3 Inheritance<br />
The concept of inheritance is essential to object orientation. When one defines a class as a subclass<br />
of an already existing class the definition of the subclass introduces an extended class, which is<br />
composed of the definitions of the superclass together with the definitions of the newly defined<br />
subclass.<br />
Through inheritance, a subclass inherits from the superclass:<br />
• Its instance variables. This also includes all invariants and their restrictions on the allowed<br />
modifications of the state.<br />
• Its operation and function definitions.<br />
• Its value and type definitions.<br />
• Its synchronization definitions as described in section 15.2.<br />
A name conflict occurs when two constructs of the same kind and with the same name are<br />
inherited from different superclasses. Name conflicts must be explicitly resolved through name<br />
qualification, i.e. prefixing the construct with the name of the superclass and a ‘-sign (back-quote)<br />
(see also section 20).<br />
Example: In the first example, we see that inheritance can be exploited to allow a class definition<br />
to be used as an abstract interface which subclasses must implement:<br />
✞<br />
class Sort<br />
instance variables<br />
protected data : seq of int<br />
operations<br />
initial_data : seq of int ==> ()<br />
initial_data (l) ==<br />
data := l;<br />
sort_ascending : () ==> ()<br />
sort_ascending () == is subclass responsibility;<br />
end Sort<br />
class SelectionSort is subclass of Sort<br />
functions<br />
130