Download presentation
Presentation is loading. Please wait.
Published byAldous Andrews Modified over 9 years ago
1
A Formal Model for Object-Oriented Software Reuse Kim Mens Programming Technology Lab Vrije Universiteit Brussel FNRS MeetingMay 6th, 1997
2
2 Contents l Object-Oriented Programming l OO Software Reuse and Evolution l Our Approach: Reuse Contracts l Software Engineering Tools based on Reuse Contracts
3
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
4 Classes and Objects DesktopFolder (HardDisk) xpos:600, ypos: 10, contents:... class DesktopFolder (name:String) instance variables xpos, ypos : Number contents : Set(DesktopItem) methods move (dx,dy:Number) = xpos.plus(dx); ypos.plus(dy) add (item:DesktopItem) = contents. include(item) addMany (group:Set(DesktopItem)) foreach item in group do self. add(item) DesktopFolder (TrashCan) xpos:580, ypos: 640, contents:... self send instances message send
5
5 Inheritance class DesktopFolder (name:String) instance variables xpos, ypos : Number contents : Set(DesktopItem) methods move (dx,dy:Number) =... add (item:DesktopItem) =... addMany (group:Set(DesktopItem)) class SizedFolder inherits from DesktopFolder instance variables size : Number methods add (item:DesktopItem) = super. add(item); size. plus(item.getsize()) super send inheritance parent class (super) child class
6
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
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
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
9 Object Modelling Technique (OMT) DesktopFolder xpos, ypos contents move add addMany SizedFolder add size class DesktopFolder (name:String) instance variables xpos, ypos : Number contents : Set(DesktopItem) methods move (dx,dy:Number) = xpos.plus(dx); ypos.plus(dy) add (item:DesktopItem) = contents. include(item) addMany (group:Set(DesktopItem)) foreach item in group do self. add(item) class SizedFolder inherits from DesktopFolder instance variables size : Number methods add (item:DesktopItem) = super. add; size. plus(item.getsize())
10
10 Our Approach: Reuse Contracts Software Reuser Software Provider 3rules for change propagation (conflict detection) 3declares how a com- ponent is reused 3declares what assumptions are made about the component 3formally, disciplined 3declares how a com- ponent can be reused; 3declares what assumptions can be made about the software; 3formally, non-coercively
11
11 Case Study: Reuse of Classes through Inheritance Class A SubClass B SubClass C Class A’ SubClass B’ SubClass C’ parent class exchange ?
12
12 Step 1: Documenting the Design documenting (part of) the specialisation interface Specialisation interface The specialisation interface declares the assumptions that can be made about a class and how it can be reused. invokes add DesktopFolder xpos, ypos contents move add addMany DesktopFolder xpos, ypos contents move add addMany {add}
13
13 Step 2: Declaring How a Class is Reused documenting different kinds of reuse The reuse operators declare the assumptions that are made about a class and how it is reused. DesktopFolder xpos, ypos, contents move add addMany {add} SizedFolder add {size} size Refinement add{+theSize} DesktopFolder xpos, ypos, contents move add addMany {add} SizedFolder add {size} size
14
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
15 size is not updated when adding many items Inconsistent Methods evolution size + item.getSize() DesktopFolder xpos, ypos contents move add addMany SizedFolder add size DesktopFolder xpos, ypos contents move add addMany SizedFolder add size size + item.getSize() OMT notation
16
16 Evolution Conflict Detection Refinement add{+size} Coarsening 3addMany {-add} Refinement add{+size} Inconsistent Methods addMany needs to be overridden too RC notation DesktopFolder xpos, ypos, contents move add addMany {add} SizedFolder add {size} size DesktopFolder xpos, ypos, contents move add addMany {add} SizedFolder add {size} size
17
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
18 Reuse contracts for inheritance Software Reuser Software Provider Refinement ¦ add{+size} Reuse contract between provider and reuser » declares how a component can be reused and is reused » formal rules for change propagation DesktopFolder xpos, ypos, contents move add addMany {add}
19
19 Software Engineering Tools based on Reuse Contracts l 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
20
20 More Information http://progwww.vub.ac.be/prog/pools/rcs/ my email: kimmens@vub.ac.be
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.