Title: A Refinement Algebra for ObjectOriented Programming
1A Refinement Algebra for Object-Oriented
Programming
Paulo Borba, Augusto Sampaio, Márcio Cornélio
- Informatics Center
- Federal University of Pernambuco
- Recife, Brazil
2Programming laws...
- state properties about programming constructs
- and
- are useful for reasoning about programs, deriving
refactorings, etc.
But is there a comprehensive set of nice laws
for OOP?
3Change attribute visibility
class C extends D pri a T ads ops end
class C extends D pub a T ads ops end
cds,c
(?) B.a, for all B ? C, does not appear in cds,c
4Relative completeness
- Laws are used to define a normal form
reduction process for ROOL programs - an empty class hierarchy except for Object, which
contains only public attributes - the types of attributes and variables are
primitive types or Object - eliminates methods, type casts, super, pri, pro
5Normal form reduction process
6Reduction process in brief
- Rename methods and attributes
- Move the code to the Object class
- Introduce trivial casts
- Eliminate super
- Eliminate casts
- Change all the declarations of object identifiers
to type Object - Eliminate method calls and declarations
7Move attribute to superclass
class B extends A ads ops end class C
extends B pub a T ads ops end
class B extends A pub a T ads
ops end class C extends B ads ops end
cds,c
(?) a is not declared by the subclasses of B in
cds (?) ...
8Moving attributes up
9Introduce trivial cast
If e C then
e
(C) e
cds,A
Useful for avoiding problems when moving up code
such as x self
10Introduce method redefinition
class B extends A ads meth m pc end
ops end class C extends B ads ops end
class B extends A ads meth m pc end
ops end class C extends B ads meth m
super.m end ops end
(?) m is not declared in ops
11Eliminating super
12Move up redefined method
class B extends A ads meth m pds b end
ops end class C extends B ads meth m pds
b end ops end
class B extends A ads meth m pds if
(self is C) ? b self is C ? b end
ops end class C extends B ads ops end
13Move up redefined method, provided
(?) private attributes and super do not
appear in b (?) super.m does not appear in
ops (?) b does not contain uncast occurrences
of self nor expressions in the form
((C)self).a for any private or protected
attribute a in ads (?) ...
14Moving up redefined methods
15Moving up methods
16Change attribute type
class C extends D pub a T ads ops end
class C extends D pub a T ads ops end
cds,c
(?) T ? T and every occurrence of a in
non-assignable expressions of ops, cds and c
is cast with T or any subtype of T declared
in cds (?) ...
17Changing types to Object
18Eliminate non trivial cast
If le B, e B, C ? B and B ? B, then
e is C le e
le (C)e
cds,A
If e B, C ? B and m is declared in B or in any
of its superclasses in cds, then
e is C e.m(e)
((C)e).m(e)
cds,A
19Eliminate method call
Let m be declared as pc. Then
e?null ? e?error pce/self (e)
e.m(e)
cds,A
(?) m is not redefined in cds (?) pc does not
contain references to super (?) all attributes in
pc are public
20Eliminating methods
21Conclusions
- Comprehensive set of laws, but not enough to
eliminate all OO constructs - Formal derivation of refactorings from the laws
- Local changes
- Separation of concerns
- Increase or decrease OO qualities
- Soundness of the laws do not rely on copy
semantics and the renaming step
22A Refinement Algebra for Object-Oriented
Programming
Paulo Borba, Augusto Sampaio, Márcio Cornélio
- Informatics Center
- Federal University of Pernambuco
- Recife, Brazil