Example - a counter object
object ctr is ctr
function n : ctr -> nat
method incr : ctr -> ctr
axioms
n(new(C)) = 0
n(incr(C)) = n(C) + 1
end
slide: The object ctr
In slide [8-ctr], we have specified a simple object ctr with
an attribute function value
(delivering the value of the counter)
and a method function incr
(that may be used to increment the value of the counter).
Abstract evaluation
-[new]->
-[incr]->
-[incr]->
-[n]->
<2, { C[n:=2] }>
slide: An example of abstract evaluation
The end result of the evaluation depicted in slide [8-ctr-evl] is
the value 2 and a context (or database) in which the
value of the counter C is (also) 2.
The database is modified in each step
in which the method incr is applied.
When the attribute function value is evaluated
the database remains unchanged, since it is merely
consulted.
Objects as abstract machines
Multiple world semantics provide a very
powerful framework in which to define the meaning of object
specifications.
Yet, as illustrated above, the reasoning involved
has a very operational flavor and lacks the appealing
simplicity of the initial algebra semantics
given for abstract data types.
As an alternative, [Goguen] propose an interpretation
of objects (with dynamic state changes) as
abstract machines.
Recall that an initial algebra semantics defines
a model in which the elements are equivalence classes
representing the abstract values of the data type.
In effect, initial models are defined only up to
isomorphism (that is, structural equivalence with
similar models).
In essence, the framework of initial algebra semantics
allows us to abstract from the particular representation
of a data type, when assigning meaning to a specification.
From this perspective it does not matter, for example, whether
integers are represented in binary or decimal notation.
The notion of abstract machines generalizes
the notion of initial algebras in that it loosens the
requirement of (structural) isomorphism,
to allow for what we may call behavioral equivalence.
The idea underlying the notion of behavioral equivalence
is to make a distinction between visible sorts
and hidden sorts and to look only at the
visible sorts to determine whether two algebras and
are behaviorally equivalent.
According to [Goguen], two algebras and
are behaviorally equivalent if and only if the result
of evaluating any expression of a visible sort in
is the same as the result of evaluating that expression
in .
Now, an abstract machine
(in the sense of Goguen and Meseguer, 1986)
is simply the equivalence class of behaviorally equivalent
algebras, or in other words the maximally abstract
characterization of the visible behavior of
an abstract data type with (hidden) states.
The notion of abstract machines is of particular relevance
as a formal framework to characterize the (implementation)
refinement relation between objects.
For example, it is easy to determine that the behavior
of a stack implemented as a list is equivalent
to the behavior of a stack implemented by a pointer array,
whereas these objects are clearly not equivalent
from a structural point of view.
Moreover, the behavior of both conform (in an abstract sense)
with the behavior specified in an algebraic way.
Together, the notions of abstract machine and behavioral equivalence
provide a formalization of the notion of information hiding
in an algebraic setting.
In the chapters that follow we will look at alternative
formalisms to explain information hiding, polymorphism
and behavioral refinement.
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.