Classboxes

1,225 views

Published on

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


(ESUG 2003, Bled)

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,225
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Classboxes

  1. 1. 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
  2. 2. Outline 1. Class extension and Package 2. Supporting Unanticipated Changes 3. The Classbox Model 4. Implementation 5. Conclusion 6. Future Work 1
  3. 3. 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
  4. 4. Class Extension: A powerful Mechanism Visitor Example: BlackPackage Opr Add Mult 3
  5. 5. Class Extension: A powerful Mechanism Visitor Example: BlackPackage BluePackage Opr acceptVisitor() Visitor doAdd() Add Mult doMult() acceptVisitor() acceptVisitor() 4
  6. 6. 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
  7. 7. 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
  8. 8. 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
  9. 9. 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
  10. 10. 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
  11. 11. 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
  12. 12. 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
  13. 13. 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
  14. 14. From within the Green Classbox GreenClassbox self.do(element.copy()) OrderedCollection do() 3 copy() 2 aCollection.copy(…) C C.new().bar() bar() 1 13
  15. 15. 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
  16. 16. 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
  17. 17. 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
  18. 18. 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
  19. 19. 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
  20. 20. 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
  21. 21. Contact Information • Alexandre Bergel (bergel@iam.unibe.ch) • Website: – http://www.iam.unibe.ch/~scg/Research/Classboxes/index.html 20

×