25.07.2014 Views

VDM-10 Language Manual

VDM-10 Language Manual

VDM-10 Language Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>VDM</strong>-<strong>10</strong> <strong>Language</strong> <strong>Manual</strong><br />

Within the class<br />

In a subclass<br />

In an arbitrary external class<br />

public protected private<br />

√ √ √<br />

√ √<br />

√<br />

×<br />

× ×<br />

Table 14.1: Summary of Access Specifier Semantics<br />

Example In the example below use of the different access specifiers is demonstrated, as well<br />

as the default access to class members. Explanation is given in the comments within the<br />

definitions.<br />

✞<br />

class A<br />

types<br />

public Atype = | | <br />

values<br />

public Avalue = <strong>10</strong>;<br />

functions<br />

public compare : nat -> Atype<br />

compare(x) ==<br />

if x < Avalue<br />

then <br />

elseif x = Avalue<br />

then <br />

else <br />

instance variables<br />

public v1: nat;<br />

private v2: bool := false;<br />

protected v3: real := 3.14;<br />

operations<br />

protected AInit : nat * bool * real ==> ()<br />

AInit(n,b,r) ==<br />

(v1 := n;<br />

v2 := b;<br />

v3 := r)<br />

2 In practice, constants will generally be static – a non-static constant would represent a constant whose value may vary<br />

from one instance of the class to another which would be more naturally represented by an instance variable.<br />

134

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

Saved successfully!

Ooh no, something went wrong!