• Save
Classboxes
Upcoming SlideShare
Loading in...5
×
 

Classboxes

on

  • 1,138 views

Bergel: Classboxes: A Minimal Module Model Supporting Local Class Extension

Bergel: Classboxes: A Minimal Module Model Supporting Local Class Extension


(ESUG 2003, Bled)

Statistics

Views

Total Views
1,138
Slideshare-icon Views on SlideShare
1,138
Embed Views
0

Actions

Likes
1
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Classboxes Classboxes Presentation Transcript

    • Classboxes: A Minimal Module Model Supporting Local Class Extension Alexandre Bergel, Stéphane Ducasse, and Roel Wuyts Software Composition Group University of Bern (Switzerland) bergel@iam.unibe.ch
    • Outline 1. Class extension and Package 2. Supporting Unanticipated Changes 3. The Classbox Model 4. Implementation 5. Conclusion 6. Future Work 1
    • Class Extension • Languages such as CLOS or Smalltalk provide a mechanism of Class Extension • A Class Extension is the ability to add or redefine methods on a class after its creation 2
    • Class Extension: A powerful Mechanism Visitor Example: BlackPackage Opr Add Mult 3
    • Class Extension: A powerful Mechanism Visitor Example: BlackPackage BluePackage Opr acceptVisitor() Visitor doAdd() Add Mult doMult() acceptVisitor() acceptVisitor() 4
    • Subclassing does not Solve it Opr Parser parse() Add Times … Add.new() Add’ Times’ … acceptVisitor() acceptVisitor() Subclasses are not referenced by the tree constructor 5
    • In Smalltalk • Class extensions are global • Any application can modify any class in the system Consequences – Conflicts may arise (e.g., two applications may add the same method) – Robustness aspect (e.g., an application may redefine a critical method) 6
    • Supporting Unanticipated Changes: Adaptation • Java, Modula-3,…have package/modules but no Class Extension • Smalltalk has Class Extension but no package/module fi Class Extension + Module ? • How to control class extensions? • How to apply a set of unanticipated changes without breaking existing clients? 7
    • Classbox Model Definition • The Classbox Model is a minimal module model supporting local class extension • A Classbox – Is a unit of scoping (i.e., it acts as a namespace) – Can define classes – Can import class definitions from other classboxes – Can define methods on classes in the scope: class extensions • Classes and methods always belong to exactly one classbox • Visibility of each element in a classbox is bound to this classbox 8
    • Classbox Model: Avoiding Conflict By having class TextClassbox import extensions local to a String classbox, conflicts are avoided URLClassbox URL WWWClassbox WWWURL String asUrl String WWWURL.new() asUrl … URL.new() … 9
    • Classbox Model: Import and Visibility Extended classes can be TextClassbox import used by classboxes String through the import relationship URLClassbox URL RedClassbox String … asUrl url = “http://www.iam.unibe.ch/~scg”.asUrl() 10
    • Classbox Model: Classbox as a Sandbox All the changes are local, so CollectionClassbox import redefinition of a critical method is limited to the Classbox OrderedCollection providing the extension do() GreenClassbox OrderedCollection do() aCollection.do(…) C C.new().foo() foo() 11
    • Classbox Model: Flattening Property Any expression executed in a CollectionClassbox import classbox will be evaluated as if OrderedCollection the whole classbox graph were do() collapsed to a single classbox. copy() 2 GreenClassbox self.do(element.copy()) OrderedCollection do() 3 aCollection.copy(…) C C.new().bar() bar() 1 12
    • From within the Green Classbox GreenClassbox self.do(element.copy()) OrderedCollection do() 3 copy() 2 aCollection.copy(…) C C.new().bar() bar() 1 13
    • Implementation • Implemented in Squeak, an open-source Smalltalk • To avoid excessive memory costs: – modify the VM • New method lookup taking some extra parameters into account such as: – Original classbox (referring the classbox where the initial expression is executed) – Collection of all the traversed classboxes 14
    • Lookup: Imports before Inheritance CollectionClassbox ImprovedClassbox PinkClassbox OrderedCollection OrderedCollection Pink do() do() foo() copy() aSortedCollection.copy() SortedCollection SortedCollection SortedCollection Pink.new().foo() Lookup of the copy() method 15
    • Lookup: Imports before Inheritance CollectionClassbox ImprovedClassbox PinkClassbox OrderedCollection OrderedCollection Pink do() do() foo() copy() 6 5 4 aSortedCollection.copy() SortedCollection SortedCollection SortedCollection 3 2 1 Pink.new().foo() Lookup of the copy() method 16
    • Lookup: Imports before Inheritance The copy() method invokes do() one CollectionClassbox ImprovedClassbox PinkClassbox OrderedCollection OrderedCollection PinkClass do() do() foo() copy() 5 4 aSortedCollection.copy() SortedCollection SortedCollection SortedCollection 3 2 1 Without any drastic optimization, a system is 60% slower 17
    • Conclusion • Definition of a module system for controlling class extensions: – Method addition and replacement are only visible in the module that defines them – Control the visibility – Support for unanticipated evolution • New method lookup – This has a price: slow performance with the current implementation 18
    • Future Work • Allow aliasing, when importing • Refined visibility control (allowing an extension to be global: evolution of a classbox) • Add multiple Classbox interfaces (clients may see a classbox under different views) • Formalization to specify the flattening property 19
    • Contact Information • Alexandre Bergel (bergel@iam.unibe.ch) • Website: – http://www.iam.unibe.ch/~scg/Research/Classboxes/index.html 20