25.07.2014 Views

VDM-10 Language Manual

VDM-10 Language Manual

VDM-10 Language Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter <strong>10</strong><br />

Instance Variables (<strong>VDM</strong>++ and <strong>VDM</strong>-RT)<br />

Both an object instantiated from a class description and the class itself can have an internal state,<br />

also called the instance variables of the object or class. In the case of objects, we also refer to this<br />

state as the global state of the object.<br />

Syntax: instance variable definitions = ‘instance’, ‘variables’,<br />

[ instance variable definition,<br />

{ ‘;’, instance variable definition } ] ;<br />

instance variable definition = access assignment definition<br />

| invariant definition ;<br />

access assignment definition = ([ access ], [ ‘static’ ]) | ([ ‘static’ ], [ access ]),<br />

assignment definition ;<br />

assignment definition = identifier, ‘:’, type, [ ‘:=’, expression ] ;<br />

invariant definition = ‘inv’, expression ;<br />

Semantics: The section describing the internal state is preceded by the keyword instance<br />

variables. A list of instance variable definitions and/or invariant definitions follows.<br />

Each instance variable definition consists of an instance variable name with its corresponding<br />

type indication and may also include an initial value and access and static specifiers.<br />

Details of the access and static specifiers can be found in section 14.4.<br />

It is possible to restrict the values of the instance variables by means of invariant definitions.<br />

Each invariant definition, involving one or more instance variables, may be defined over<br />

the values of the instance variables of objects of a class. All instance variables in the class<br />

including those inherited from superclasses are visible in the invariant expression. Each invariant<br />

definition must be a boolean expression that limits the values of the instance variables<br />

to those where the expression is true. All invariant expressions must be true during the entire<br />

lifetime of each object of the class.<br />

83

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!