A Formal Model for ObjectOriented Software Reuse Kim
A Formal Model for Object-Oriented Software Reuse Kim Mens Programming Technology Lab Vrije Universiteit Brussel FNRS Meeting May 6 th, 1997
2 Contents Object-Oriented Programming l OO Software Reuse and Evolution l Our Approach: Reuse Contracts l Software Engineering Tools based on Reuse Contracts l
3 Object-Oriented Programming • Objects contain both data (instance variables) and operations (methods). • Operations can be invoked and variables retrieved by means of message sending. • Classes are “templates” for objects. • Objects of the same class (instances) have the same implementation, but different internal state. • The implementation of existing classes can be reused (specialised) by means of inheritance.
4 Classes and Objects instances class Desktop. Folder(name: String) instance variables Desktop. Folder(Hard. Disk) xpos, ypos : Number xpos: 600, ypos: 10, contents : Set(Desktop. Item) contents: . . . methods move(dx, dy: Number) = xpos. plus(dx); ypos. plus(dy) Desktop. Folder(Trash. Can) add(item: Desktop. Item) = xpos: 580, ypos: 640, contents. include(item) contents: . . . add. Many(group: Set(Desktop. Item)) foreach item in group message send do self. add(item) self send
5 Inheritance class Desktop. Folder(name: String) parent class (super) instance variables xpos, ypos : Number contents : Set(Desktop. Item) methods inheritance move(dx, dy: Number) =. . . add(item: Desktop. Item) =. . . class Sized. Folder inherits from Desktop. Folder add. Many(group: Set(Desktop. Item)) instance variables size : Number child class methods add(item: Desktop. Item) = super. add(item); super send size. plus(item. getsize())
6 Software Reuse and Evolution Software Reuse = Reusing existing software parts in new systems. Software Evolution = Updating system parts by more recent versions. Both evolution and reuse give rise to similar problems.
7 What can go wrong. . . 4 Ariane 4 » well-tested software » proven correctly 4 Ariane 5 » reuse of pieces of Ariane 4 software » result: trivial error (floating point error), large consequences 4 What happened ? » changed flight specifications
8 OO Software Reuse and Evolution l Current notations/methodologies/tools insufficiently support software reuse – support code reuse rather than design reuse – insufficiently document important dependencies – are too informal l Need for contract between software providers and reusers. – how can a software component be reused? – how is it actually reused?
9 Object Modelling Technique (OMT) class Desktop. Folder(name: String) instance variables xpos, ypos : Number contents : Set(Desktop. Item) methods move(dx, dy: Number) = xpos. plus(dx); ypos. plus(dy) add(item: Desktop. Item) = contents. include(item) add. Many(group: Set(Desktop. Item)) class Sized. Folder foreach item in group inherits from Desktop. Folder do self. add(item) instance variables size : Number methods add(item: Desktop. Item) = super. add; size. plus(item. getsize()) Desktop. Folder xpos, ypos contents move add. Many Sized. Folder size add
10 Our Approach: Reuse Contracts Software Provider Software Reuser 3 declares how a component can be reused; 3 declares what assumptions can be made about the software; 3 formally, non-coercively 3 declares how a component is reused 3 declares what assumptions are made about the component 3 formally, disciplined 3 rules for change propagation (conflict detection)
11 Case Study: Reuse of Classes through Inheritance Class A’ parent class exchange ? Sub. Class B’ Sub. Class C’
12 Step 1: Documenting the Design Desktop. Folder Sp xpos, ypos contents move add. Many ec in ialis ter a fa tion ce documenting (part of) the specialisation interface Desktop. Folder xpos, ypos contents move invokes add. Many {add} add The specialisation interface declares the assumptions that can be made about a class and how it can be reused.
13 Step 2: Declaring How a Class is Reused Desktop. Folder xpos, ypos, contents move add. Many {add} documenting different kinds of reuse Desktop. Folder xpos, ypos, contents move add. Many {add} Refinement 3 add{+the. Size} Sized. Folder size add {size} The reuse operators declare the assumptions that are made about a class and how it is reused.
14 Different Kinds of Reuse 3 Design “specialising” » Concretisation: replacing dummy or default method implementations by more specific ones » Extension: adding new behaviour » Refinement: refining the overall design by adding method dependencies 3 Design “generalising” » Abstraction: opposite of concretisation » Cancellation: removing existing behaviour » Coarsening: removing method dependencies
15 Inconsistent Methods Desktop. Folder xpos, ypos contents move add. Many Sized. Folder OMT notation Desktop. Folder evolution size + item. get. Size() xpos, ypos contents move add. Many Sized. Folder size add size + item. get. Size() size is not updated when adding many items
16 Evolution Conflict Detection Coarsening Desktop. Folder xpos, ypos, contents move add. Many {add} 3 add. Many {-add} Desktop. Folder xpos, ypos, contents move add. Many {add} Refinement 3 add{+size} Sized. Folder RC notation 3 add{+size} Sized. Folder size add {size} Inconsistent Methods add. Many needs to be overridden too
17 Step 3: Formal Model & Rules for Conflict Detection • Formal model of … reuse contracts, reuse operators, and applicability • Formal rules for. . . detecting conflicts on parent class exchange automated conflict checking possible !
18 Reuse contracts for inheritance Software Provider Software Reuser Desktop. Folder xpos, ypos, contents move add. Many {add} Refinement ¦ add{+size} Reuse contract between provider and reuser » declares how a component can be reused and is reused » formal rules for change propagation
19 Software Engineering Tools based on Reuse Contracts Impact Analysis & Conflict Detection l Documenting Structure & Design of Software l Extracting Reuse Contracts (from source code) Þ Reverse Engineering l Verifying Compliance (of code) to Reuse Contracts Þ Enforcing Design l Generating Code l Quality Assessment of Software Design l
20 More Information http: //progwww. vub. ac. be/prog/pools/rcs/ my email: kimmens@vub. ac. be
- Slides: 20