SlideShare a Scribd company logo
1 of 25
Download to read offline
Classbox/J: Controlling the
 Scope of Change in Java


Alexandre Bergel,
Stéphane Ducasse and
Oscar Nierstrasz

bergel@iam.unibe.ch
Outline

 1. AWT and Swing Anomalies

 2. Classbox/J

 3. Properties of Classboxes

 4. Swing as a Classbox

 5. Implementation

 6. Conclusion


Alexandre Bergel               2
Presentation of AWT
     java.awt

                                         Component


                                                           Button
                                         Container
                        Window
        Frame



     In the AWT framework:
 •
       – Widgets are components (i.e., inherit from Component)
       – A frame is a window (Frame is a subclass of Window)




Alexandre Bergel                     3
Problem: Broken Inheritance in Swing
    java.awt

                                 Component


                                              Button
                                 Container
                   Window
        Frame

   javax.swing
                                 JComponent
                   JWindow
        JFrame
                                              JButton




Alexandre Bergel             4
Problem: Code Duplication
                                                              Code Duplication
    java.awt

                                              Component


                                                              Button
                                               Container
                        Window
        Frame

   javax.swing
                                              JComponent
                        JWindow
        JFrame                               accessibleCont
                     accessibleContext
 accessibleContext                                            JButton
                                             ext
                                             update()
                     rootPane
 rootPane
                     update()
 update()
                     setLayout()
 setLayout()
                     ...
 ...

Alexandre Bergel                         5
Problem: Explicit Type Checks and Casts
    public class Container extends Component {
      Component components[] = new Component [0];
      public Component add (Component comp) {...}
    }

    public class JComponent extends Container {
      public void paintChildren (Graphics g) {
         for (; i>=0 ; i--) {
           Component comp = getComponent (i);
           isJComponent = (comp instanceof JComponent);
           ...
           ((JComponent) comp).getBounds();
         }
      }}


Alexandre Bergel           6
We need to Support Unanticipated Changes

     AWT couldn’t be enhanced without risk of breaking
 •
     existing code.

     Swing is, therefore, built on the top of AWT using
 •
     subclassing.

     As a result, Swing is a big mess internally!
 •


     We need a mechanism to support unanticipated changes.
 •




Alexandre Bergel                   7
Classbox/J

     Module system for Java allowing classes to be refined
 •
     without breaking former clients.

     A classbox is like a package where:
 •

       – a class defined or imported within a classbox p can be imported
         by another classbox (transitive import).

       – class members can be added or redefined on an imported class
         with the keyword refine.

       – a refined method can access its original behavior using the
         original keyword


Alexandre Bergel                      8
Refining Classes (1 / 2)

    A classbox widgetsCB

         package widgetsCB;

         public class Component {
         	

 public void update() {this.paint();}
           	

         	

 public void paint () {/*Old code*/}
           	

         }

         public class Button extends Component {
         	

 ...
           	

         }



Alexandre Bergel              9
Refining Classes (2 / 2)

    Widget enhancements defined in NewWidgetsCB:

         package NewWidgetsCB;
         import widgetsCB.Component;
         import widgetsCB.Button;

         refine Component {
                	

 Variable addition */
                  /*
         	

 private ComponentUI lookAndFeel;
           	


         	

 /* Redefinition of paint() */
           	

         	

 public void paint() {
           	

         	

 	

 /* Code that uses lookAndFeel*/ }
           	

         }

Alexandre Bergel               10
Multiple Versions of Classes
                                                                        Import
                                                                       class refinement
                                                                  C
    widgetsCB                                 NewWidgetsCB
                                                 Component
                   Component
                                                lookAndFeel
                   paint()
                   update()                     paint()


                      Button                       Button

             new Button(“Ok”).update()           new Button(“Ok”).update()




Alexandre Bergel                         11
Import over Inheritance
                                                                        Import
                                                                       class refinement
                                                                  C
    widgetsCB                                 NewWidgetsCB
                                                 Component
                   Component
                                                lookAndFeel
                   paint()
                   update()    4                              3
                                                paint()


                      Button                       Button
                               2                              1
             new Button(“Ok”).update()           new Button(“Ok”).update()




           Lookup of the update() method triggered within
       1   enhWidgetsCB.

Alexandre Bergel                         12
But update() calls paint()
                                                                        Import
                                                                       class refinement
                                                                  C
    widgetsCB                                 NewWidgetsCB
                                                 Component
                   Component
                                                lookAndFeel
                   paint()
                   update()                     paint()
                                                              3


                      Button                       Button
                               2                              1
             new Button(“Ok”).update()           new Button(“Ok”).update()




           Lookup of the paint() method triggered within
     1
           enhWidgetsCB

Alexandre Bergel                         13
Old and New Clients at the Same Time
                                                                     Import
                                                                    class refinement
                                                                C
    widgetsCB                                   NewWidgetsCB
                                                   Component
                   Component
                                                  lookAndFeel
                   paint()
                   update()                       paint()


                      Button                         Button



                                                NewGUIAppCB
    OldGUIAppCB

                                                    Button      NewGUIApp
            Button             OldGUIApp




Alexandre Bergel                           14
Properties of Classboxes

     Minimal extension of the Java syntax (transitive import,
 •
     refine and original keywords).

     Refinements are confined to the classbox that define them
 •
     and to classboxes that import refined classes.

     Method redefinitions have precedence over previous
 •
     definitions.

     Classes can be refined without risk of breaking former
 •
     clients.


Alexandre Bergel                 15
Swing Refactored as a Classbox
    AwtCB

                                               Component


                                      Container                  Button
                     Window
           Frame

    SwingCB
                                               Component
                      Window                 accessibleContext
           Frame                             component
                   rootPane
                                                                 Button
                                             update()
                   setLayout()               add(Component)
                   setRootPane()             remove(Component)
                   setContentPane()
                   ...



Alexandre Bergel                        16
Swing Refactoring

     6500 lines of code refactored over 4 classes.
 •


     Inheritance defined in AwtCB is fully preserved in
 •
     SwingCB:
       – In SwingCB, every widget is a component (i.e., inherits from the
         extended AWT Component).
       – The property “a frame is a window” is true in SwingCB.

     Removed duplicated code: the refined Frame is 29 %
 •
     smaller than the original JFrame.

 •   Explicit type checks like obj instanceof JComponent and
     (JComponent)obj are avoided.

Alexandre Bergel                      17
Naive Implementation

     Based on source code manipulation.
 •


     The method call stack is introspected to determine the
 •
     right version of a method to be triggered.

     No cost for method additions, however slowdown of 1000
 •
     times when calling a redefined method.

     However, much better results were obtained in Smalltalk.
 •
     5 byte-codes are added to redefined methods (see our
     previous work).


Alexandre Bergel                18
Conclusion

     Classboxes delimit visibility of a change and avoid impacting
 •
     clients that should not be affected.

     Java is extended with two new keywords and transitive
 •
     import.

     Large case study showing how classboxes can be more
 •
     powerful than inheritance to support unanticipated
     changes.

     Performance could be improved by modifying the VM.
 •




Alexandre Bergel                 19
We need an alternative to
    inheritance to support
    unanticipated changes!




    Alexandre Bergel:
    bergel@iam.unibe.ch

    google “classboxes”



Alexandre Bergel                20
END




Alexandre Bergel   21
A JWidget is not necessary a JComponent
    java.awt

                                     Component


                                                  Button
                                     Container
                     Window
        Frame

   javax.swing
                                     JComponent
                     JWindow
        JFrame
                                                  JButton


                   Are not subclasses of JComponent
Alexandre Bergel                22
A JFrame is not a JWindow
    java.awt

                                   Component


                                                 Button
                                   Container
                   Window
        Frame

   javax.swing
                                   JComponent
                   JWindow
        JFrame
                                                 JButton

   Missing inheritance link between JFrame and JWindow

Alexandre Bergel              23
AWT and Swing Anomalies

     Features defined in JWindow are duplicated in JFrame (half
 •
     of JWindow code is in JFrame).
     The Swing design breaks the AWT inheritance relation:
 •
       – AWT: a Window is a Component
       – Swing: a JWindow is not a JComponent
     Need of explicit type checks and casts in Swing:
 •
       – For instance a JWindow needs to check if its elements are issued
         from Swing or not before rendering them
       – 82 type checks (instanceof) and 151 cast to (JComponent)




Alexandre Bergel                     24
Method Call Stack Introspected

 NewWidgetsCB and WidgetsCB define the paint method:
      package WidgetsCB;
      public class Component {
       public void paint() {

      	

        	

   if (ClassboxInfo.methodVisible (
      	

        	

        “NewWidgetsCB”, “Component”, “paint”)){
      	

        	

   	

    //Enhanced paint
      	

        	

   }
      	

        	

      	

        	

   if (ClassboxInfo.methodVisible (
      	

        	

        “WidgetsCB”, “Component”, “paint”)){
      	

        	

   	

    //Original paint
      	

        	

   }}}

Alexandre Bergel                   25

More Related Content

What's hot

GWT Training - Session 2/3
GWT Training - Session 2/3GWT Training - Session 2/3
GWT Training - Session 2/3Faiz Bashir
 
Building a web application with ontinuation monads
Building a web application with ontinuation monadsBuilding a web application with ontinuation monads
Building a web application with ontinuation monadsSeitaro Yuuki
 
GWT Training - Session 1/3
GWT Training - Session 1/3GWT Training - Session 1/3
GWT Training - Session 1/3Faiz Bashir
 
On Processors, Compilers and @Configurations
On Processors, Compilers and @ConfigurationsOn Processors, Compilers and @Configurations
On Processors, Compilers and @ConfigurationsNetcetera
 
Are app servers still fascinating
Are app servers still fascinatingAre app servers still fascinating
Are app servers still fascinatingAntonio Goncalves
 
React 16: new features and beyond
React 16: new features and beyondReact 16: new features and beyond
React 16: new features and beyondArtjoker
 
To inject or not to inject: CDI is the question
To inject or not to inject: CDI is the questionTo inject or not to inject: CDI is the question
To inject or not to inject: CDI is the questionAntonio Goncalves
 
Java Graphics Programming
Java Graphics ProgrammingJava Graphics Programming
Java Graphics ProgrammingRiccardo Cardin
 
E catt tutorial
E catt tutorialE catt tutorial
E catt tutorialNaveen Raj
 
Generic UXD Legos - Selenium Conference 2015
Generic UXD Legos - Selenium Conference 2015Generic UXD Legos - Selenium Conference 2015
Generic UXD Legos - Selenium Conference 2015Selena Phillips
 
Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web ToolkitsYiguang Hu
 
GR8Conf 2009: Industrial Strength Groovy by Paul King
GR8Conf 2009: Industrial Strength Groovy by Paul KingGR8Conf 2009: Industrial Strength Groovy by Paul King
GR8Conf 2009: Industrial Strength Groovy by Paul KingGR8Conf
 
13 gui development
13 gui development13 gui development
13 gui developmentAPU
 

What's hot (19)

Swings
SwingsSwings
Swings
 
GWT Training - Session 2/3
GWT Training - Session 2/3GWT Training - Session 2/3
GWT Training - Session 2/3
 
CDI: How do I ?
CDI: How do I ?CDI: How do I ?
CDI: How do I ?
 
Building a web application with ontinuation monads
Building a web application with ontinuation monadsBuilding a web application with ontinuation monads
Building a web application with ontinuation monads
 
GWT Training - Session 1/3
GWT Training - Session 1/3GWT Training - Session 1/3
GWT Training - Session 1/3
 
On Processors, Compilers and @Configurations
On Processors, Compilers and @ConfigurationsOn Processors, Compilers and @Configurations
On Processors, Compilers and @Configurations
 
Are app servers still fascinating
Are app servers still fascinatingAre app servers still fascinating
Are app servers still fascinating
 
Android native gl
Android native glAndroid native gl
Android native gl
 
React 16: new features and beyond
React 16: new features and beyondReact 16: new features and beyond
React 16: new features and beyond
 
To inject or not to inject: CDI is the question
To inject or not to inject: CDI is the questionTo inject or not to inject: CDI is the question
To inject or not to inject: CDI is the question
 
Java Swing
Java SwingJava Swing
Java Swing
 
Java Graphics Programming
Java Graphics ProgrammingJava Graphics Programming
Java Graphics Programming
 
Spring 3 to 4
Spring 3 to 4Spring 3 to 4
Spring 3 to 4
 
E catt tutorial
E catt tutorialE catt tutorial
E catt tutorial
 
Generic UXD Legos - Selenium Conference 2015
Generic UXD Legos - Selenium Conference 2015Generic UXD Legos - Selenium Conference 2015
Generic UXD Legos - Selenium Conference 2015
 
XMPPart5
XMPPart5XMPPart5
XMPPart5
 
Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web Toolkits
 
GR8Conf 2009: Industrial Strength Groovy by Paul King
GR8Conf 2009: Industrial Strength Groovy by Paul KingGR8Conf 2009: Industrial Strength Groovy by Paul King
GR8Conf 2009: Industrial Strength Groovy by Paul King
 
13 gui development
13 gui development13 gui development
13 gui development
 

Viewers also liked

2008 Sccc Inheritance
2008 Sccc Inheritance2008 Sccc Inheritance
2008 Sccc Inheritancebergel
 
Test beautycleanness
Test beautycleannessTest beautycleanness
Test beautycleannessbergel
 
tres fotos
tres fotostres fotos
tres fotossara356
 
2006 Small Scheme
2006 Small Scheme2006 Small Scheme
2006 Small Schemebergel
 
2006 Esug Omnibrowser
2006 Esug Omnibrowser2006 Esug Omnibrowser
2006 Esug Omnibrowserbergel
 
Multi dimensional profiling
Multi dimensional profilingMulti dimensional profiling
Multi dimensional profilingbergel
 
2008 Sccc Smalltalk
2008 Sccc Smalltalk2008 Sccc Smalltalk
2008 Sccc Smalltalkbergel
 

Viewers also liked (7)

2008 Sccc Inheritance
2008 Sccc Inheritance2008 Sccc Inheritance
2008 Sccc Inheritance
 
Test beautycleanness
Test beautycleannessTest beautycleanness
Test beautycleanness
 
tres fotos
tres fotostres fotos
tres fotos
 
2006 Small Scheme
2006 Small Scheme2006 Small Scheme
2006 Small Scheme
 
2006 Esug Omnibrowser
2006 Esug Omnibrowser2006 Esug Omnibrowser
2006 Esug Omnibrowser
 
Multi dimensional profiling
Multi dimensional profilingMulti dimensional profiling
Multi dimensional profiling
 
2008 Sccc Smalltalk
2008 Sccc Smalltalk2008 Sccc Smalltalk
2008 Sccc Smalltalk
 

Similar to 2005 Oopsla Classboxj

Unit-2 swing and mvc architecture
Unit-2 swing and mvc architectureUnit-2 swing and mvc architecture
Unit-2 swing and mvc architectureAmol Gaikwad
 
Ajp notes-chapter-02
Ajp notes-chapter-02Ajp notes-chapter-02
Ajp notes-chapter-02Ankit Dubey
 
Console to GUI
Console to GUIConsole to GUI
Console to GUIChloe Choi
 
MEF Deep Dive by Piotr Wlodek
MEF Deep Dive by Piotr WlodekMEF Deep Dive by Piotr Wlodek
MEF Deep Dive by Piotr Wlodekinfusiondev
 
Lab 2: Importing requirements artifacts from a CSV file
Lab 2: Importing requirements artifacts from a CSV file Lab 2: Importing requirements artifacts from a CSV file
Lab 2: Importing requirements artifacts from a CSV file IBM Rational software
 
GWT training session 2
GWT training session 2GWT training session 2
GWT training session 2SNEHAL MASNE
 
Java session10
Java session10Java session10
Java session10Niit Care
 
Making React Native UI Components with Swift
Making React Native UI Components with SwiftMaking React Native UI Components with Swift
Making React Native UI Components with SwiftRay Deck
 
Patches_Presentation.pptx
Patches_Presentation.pptxPatches_Presentation.pptx
Patches_Presentation.pptxssuser46d193
 
Advance Java Programming (CM5I) 2.Swing
Advance Java Programming (CM5I) 2.SwingAdvance Java Programming (CM5I) 2.Swing
Advance Java Programming (CM5I) 2.SwingPayal Dungarwal
 
Building kubectl plugins with Quarkus | DevNation Tech Talk
Building kubectl plugins with Quarkus | DevNation Tech TalkBuilding kubectl plugins with Quarkus | DevNation Tech Talk
Building kubectl plugins with Quarkus | DevNation Tech TalkRed Hat Developers
 
intro_gui
intro_guiintro_gui
intro_guifilipb2
 
TestExec SL 7.1
TestExec SL 7.1TestExec SL 7.1
TestExec SL 7.1Interlatin
 
What is new with JavaScript in Gnome: The 2021 edition
What is new with JavaScript in Gnome: The 2021 editionWhat is new with JavaScript in Gnome: The 2021 edition
What is new with JavaScript in Gnome: The 2021 editionIgalia
 

Similar to 2005 Oopsla Classboxj (20)

Unit-2 swing and mvc architecture
Unit-2 swing and mvc architectureUnit-2 swing and mvc architecture
Unit-2 swing and mvc architecture
 
Ajp notes-chapter-02
Ajp notes-chapter-02Ajp notes-chapter-02
Ajp notes-chapter-02
 
Console to GUI
Console to GUIConsole to GUI
Console to GUI
 
Image filters
Image filtersImage filters
Image filters
 
MEF Deep Dive by Piotr Wlodek
MEF Deep Dive by Piotr WlodekMEF Deep Dive by Piotr Wlodek
MEF Deep Dive by Piotr Wlodek
 
Lab 2: Importing requirements artifacts from a CSV file
Lab 2: Importing requirements artifacts from a CSV file Lab 2: Importing requirements artifacts from a CSV file
Lab 2: Importing requirements artifacts from a CSV file
 
GWT training session 2
GWT training session 2GWT training session 2
GWT training session 2
 
Chapter 02: Eclipse Vert.x - Java First Verticle
Chapter 02: Eclipse Vert.x - Java First VerticleChapter 02: Eclipse Vert.x - Java First Verticle
Chapter 02: Eclipse Vert.x - Java First Verticle
 
Awt and swing in java
Awt and swing in javaAwt and swing in java
Awt and swing in java
 
Java session10
Java session10Java session10
Java session10
 
Making React Native UI Components with Swift
Making React Native UI Components with SwiftMaking React Native UI Components with Swift
Making React Native UI Components with Swift
 
13457272.ppt
13457272.ppt13457272.ppt
13457272.ppt
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Patches_Presentation.pptx
Patches_Presentation.pptxPatches_Presentation.pptx
Patches_Presentation.pptx
 
Advance Java Programming (CM5I) 2.Swing
Advance Java Programming (CM5I) 2.SwingAdvance Java Programming (CM5I) 2.Swing
Advance Java Programming (CM5I) 2.Swing
 
Building kubectl plugins with Quarkus | DevNation Tech Talk
Building kubectl plugins with Quarkus | DevNation Tech TalkBuilding kubectl plugins with Quarkus | DevNation Tech Talk
Building kubectl plugins with Quarkus | DevNation Tech Talk
 
intro_gui
intro_guiintro_gui
intro_gui
 
Acceleo Code Generation
Acceleo Code GenerationAcceleo Code Generation
Acceleo Code Generation
 
TestExec SL 7.1
TestExec SL 7.1TestExec SL 7.1
TestExec SL 7.1
 
What is new with JavaScript in Gnome: The 2021 edition
What is new with JavaScript in Gnome: The 2021 editionWhat is new with JavaScript in Gnome: The 2021 edition
What is new with JavaScript in Gnome: The 2021 edition
 

More from bergel

Building Neural Network Through Neuroevolution
Building Neural Network Through NeuroevolutionBuilding Neural Network Through Neuroevolution
Building Neural Network Through Neuroevolutionbergel
 
Roassal presentation
Roassal presentationRoassal presentation
Roassal presentationbergel
 
2011 famoosr
2011 famoosr2011 famoosr
2011 famoosrbergel
 
2011 ecoop
2011 ecoop2011 ecoop
2011 ecoopbergel
 
Profiling blueprints
Profiling blueprintsProfiling blueprints
Profiling blueprintsbergel
 
The Pharo Programming Language
The Pharo Programming LanguageThe Pharo Programming Language
The Pharo Programming Languagebergel
 
Presentation of Traits
Presentation of TraitsPresentation of Traits
Presentation of Traitsbergel
 
2006 Seaside
2006 Seaside2006 Seaside
2006 Seasidebergel
 
2004 Esug Prototalk
2004 Esug Prototalk2004 Esug Prototalk
2004 Esug Prototalkbergel
 

More from bergel (9)

Building Neural Network Through Neuroevolution
Building Neural Network Through NeuroevolutionBuilding Neural Network Through Neuroevolution
Building Neural Network Through Neuroevolution
 
Roassal presentation
Roassal presentationRoassal presentation
Roassal presentation
 
2011 famoosr
2011 famoosr2011 famoosr
2011 famoosr
 
2011 ecoop
2011 ecoop2011 ecoop
2011 ecoop
 
Profiling blueprints
Profiling blueprintsProfiling blueprints
Profiling blueprints
 
The Pharo Programming Language
The Pharo Programming LanguageThe Pharo Programming Language
The Pharo Programming Language
 
Presentation of Traits
Presentation of TraitsPresentation of Traits
Presentation of Traits
 
2006 Seaside
2006 Seaside2006 Seaside
2006 Seaside
 
2004 Esug Prototalk
2004 Esug Prototalk2004 Esug Prototalk
2004 Esug Prototalk
 

Recently uploaded

Sales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for SuccessSales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for SuccessAggregage
 
/:Call Girls In Jaypee Siddharth - 5 Star Hotel New Delhi ➥9990211544 Top Esc...
/:Call Girls In Jaypee Siddharth - 5 Star Hotel New Delhi ➥9990211544 Top Esc.../:Call Girls In Jaypee Siddharth - 5 Star Hotel New Delhi ➥9990211544 Top Esc...
/:Call Girls In Jaypee Siddharth - 5 Star Hotel New Delhi ➥9990211544 Top Esc...lizamodels9
 
Call Girls in Mehrauli Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Mehrauli Delhi 💯Call Us 🔝8264348440🔝Call Girls in Mehrauli Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Mehrauli Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableDipal Arora
 
Vip Female Escorts Noida 9711199171 Greater Noida Escorts Service
Vip Female Escorts Noida 9711199171 Greater Noida Escorts ServiceVip Female Escorts Noida 9711199171 Greater Noida Escorts Service
Vip Female Escorts Noida 9711199171 Greater Noida Escorts Serviceankitnayak356677
 
GD Birla and his contribution in management
GD Birla and his contribution in managementGD Birla and his contribution in management
GD Birla and his contribution in managementchhavia330
 
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service JamshedpurVIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service JamshedpurSuhani Kapoor
 
Grateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfGrateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfPaul Menig
 
Banana Powder Manufacturing Plant Project Report 2024 Edition.pptx
Banana Powder Manufacturing Plant Project Report 2024 Edition.pptxBanana Powder Manufacturing Plant Project Report 2024 Edition.pptx
Banana Powder Manufacturing Plant Project Report 2024 Edition.pptxgeorgebrinton95
 
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...anilsa9823
 
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...lizamodels9
 
Lean: From Theory to Practice — One City’s (and Library’s) Lean Story… Abridged
Lean: From Theory to Practice — One City’s (and Library’s) Lean Story… AbridgedLean: From Theory to Practice — One City’s (and Library’s) Lean Story… Abridged
Lean: From Theory to Practice — One City’s (and Library’s) Lean Story… AbridgedKaiNexus
 
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In.../:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...lizamodels9
 
7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...Paul Menig
 
Call Girls in Gomti Nagar - 7388211116 - With room Service
Call Girls in Gomti Nagar - 7388211116  - With room ServiceCall Girls in Gomti Nagar - 7388211116  - With room Service
Call Girls in Gomti Nagar - 7388211116 - With room Servicediscovermytutordmt
 
(8264348440) 🔝 Call Girls In Mahipalpur 🔝 Delhi NCR
(8264348440) 🔝 Call Girls In Mahipalpur 🔝 Delhi NCR(8264348440) 🔝 Call Girls In Mahipalpur 🔝 Delhi NCR
(8264348440) 🔝 Call Girls In Mahipalpur 🔝 Delhi NCRsoniya singh
 
Eni 2024 1Q Results - 24.04.24 business.
Eni 2024 1Q Results - 24.04.24 business.Eni 2024 1Q Results - 24.04.24 business.
Eni 2024 1Q Results - 24.04.24 business.Eni
 
Progress Report - Oracle Database Analyst Summit
Progress  Report - Oracle Database Analyst SummitProgress  Report - Oracle Database Analyst Summit
Progress Report - Oracle Database Analyst SummitHolger Mueller
 

Recently uploaded (20)

Sales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for SuccessSales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for Success
 
/:Call Girls In Jaypee Siddharth - 5 Star Hotel New Delhi ➥9990211544 Top Esc...
/:Call Girls In Jaypee Siddharth - 5 Star Hotel New Delhi ➥9990211544 Top Esc.../:Call Girls In Jaypee Siddharth - 5 Star Hotel New Delhi ➥9990211544 Top Esc...
/:Call Girls In Jaypee Siddharth - 5 Star Hotel New Delhi ➥9990211544 Top Esc...
 
Call Girls in Mehrauli Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Mehrauli Delhi 💯Call Us 🔝8264348440🔝Call Girls in Mehrauli Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Mehrauli Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
 
Vip Female Escorts Noida 9711199171 Greater Noida Escorts Service
Vip Female Escorts Noida 9711199171 Greater Noida Escorts ServiceVip Female Escorts Noida 9711199171 Greater Noida Escorts Service
Vip Female Escorts Noida 9711199171 Greater Noida Escorts Service
 
GD Birla and his contribution in management
GD Birla and his contribution in managementGD Birla and his contribution in management
GD Birla and his contribution in management
 
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service JamshedpurVIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
 
Grateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfGrateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdf
 
Banana Powder Manufacturing Plant Project Report 2024 Edition.pptx
Banana Powder Manufacturing Plant Project Report 2024 Edition.pptxBanana Powder Manufacturing Plant Project Report 2024 Edition.pptx
Banana Powder Manufacturing Plant Project Report 2024 Edition.pptx
 
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
 
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
 
Lean: From Theory to Practice — One City’s (and Library’s) Lean Story… Abridged
Lean: From Theory to Practice — One City’s (and Library’s) Lean Story… AbridgedLean: From Theory to Practice — One City’s (and Library’s) Lean Story… Abridged
Lean: From Theory to Practice — One City’s (and Library’s) Lean Story… Abridged
 
Best Practices for Implementing an External Recruiting Partnership
Best Practices for Implementing an External Recruiting PartnershipBest Practices for Implementing an External Recruiting Partnership
Best Practices for Implementing an External Recruiting Partnership
 
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In.../:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
 
7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...
 
Call Girls in Gomti Nagar - 7388211116 - With room Service
Call Girls in Gomti Nagar - 7388211116  - With room ServiceCall Girls in Gomti Nagar - 7388211116  - With room Service
Call Girls in Gomti Nagar - 7388211116 - With room Service
 
KestrelPro Flyer Japan IT Week 2024 (English)
KestrelPro Flyer Japan IT Week 2024 (English)KestrelPro Flyer Japan IT Week 2024 (English)
KestrelPro Flyer Japan IT Week 2024 (English)
 
(8264348440) 🔝 Call Girls In Mahipalpur 🔝 Delhi NCR
(8264348440) 🔝 Call Girls In Mahipalpur 🔝 Delhi NCR(8264348440) 🔝 Call Girls In Mahipalpur 🔝 Delhi NCR
(8264348440) 🔝 Call Girls In Mahipalpur 🔝 Delhi NCR
 
Eni 2024 1Q Results - 24.04.24 business.
Eni 2024 1Q Results - 24.04.24 business.Eni 2024 1Q Results - 24.04.24 business.
Eni 2024 1Q Results - 24.04.24 business.
 
Progress Report - Oracle Database Analyst Summit
Progress  Report - Oracle Database Analyst SummitProgress  Report - Oracle Database Analyst Summit
Progress Report - Oracle Database Analyst Summit
 

2005 Oopsla Classboxj

  • 1. Classbox/J: Controlling the Scope of Change in Java Alexandre Bergel, Stéphane Ducasse and Oscar Nierstrasz bergel@iam.unibe.ch
  • 2. Outline 1. AWT and Swing Anomalies 2. Classbox/J 3. Properties of Classboxes 4. Swing as a Classbox 5. Implementation 6. Conclusion Alexandre Bergel 2
  • 3. Presentation of AWT java.awt Component Button Container Window Frame In the AWT framework: • – Widgets are components (i.e., inherit from Component) – A frame is a window (Frame is a subclass of Window) Alexandre Bergel 3
  • 4. Problem: Broken Inheritance in Swing java.awt Component Button Container Window Frame javax.swing JComponent JWindow JFrame JButton Alexandre Bergel 4
  • 5. Problem: Code Duplication Code Duplication java.awt Component Button Container Window Frame javax.swing JComponent JWindow JFrame accessibleCont accessibleContext accessibleContext JButton ext update() rootPane rootPane update() update() setLayout() setLayout() ... ... Alexandre Bergel 5
  • 6. Problem: Explicit Type Checks and Casts public class Container extends Component { Component components[] = new Component [0]; public Component add (Component comp) {...} } public class JComponent extends Container { public void paintChildren (Graphics g) { for (; i>=0 ; i--) { Component comp = getComponent (i); isJComponent = (comp instanceof JComponent); ... ((JComponent) comp).getBounds(); } }} Alexandre Bergel 6
  • 7. We need to Support Unanticipated Changes AWT couldn’t be enhanced without risk of breaking • existing code. Swing is, therefore, built on the top of AWT using • subclassing. As a result, Swing is a big mess internally! • We need a mechanism to support unanticipated changes. • Alexandre Bergel 7
  • 8. Classbox/J Module system for Java allowing classes to be refined • without breaking former clients. A classbox is like a package where: • – a class defined or imported within a classbox p can be imported by another classbox (transitive import). – class members can be added or redefined on an imported class with the keyword refine. – a refined method can access its original behavior using the original keyword Alexandre Bergel 8
  • 9. Refining Classes (1 / 2) A classbox widgetsCB package widgetsCB; public class Component { public void update() {this.paint();} public void paint () {/*Old code*/} } public class Button extends Component { ... } Alexandre Bergel 9
  • 10. Refining Classes (2 / 2) Widget enhancements defined in NewWidgetsCB: package NewWidgetsCB; import widgetsCB.Component; import widgetsCB.Button; refine Component { Variable addition */ /* private ComponentUI lookAndFeel; /* Redefinition of paint() */ public void paint() { /* Code that uses lookAndFeel*/ } } Alexandre Bergel 10
  • 11. Multiple Versions of Classes Import class refinement C widgetsCB NewWidgetsCB Component Component lookAndFeel paint() update() paint() Button Button new Button(“Ok”).update() new Button(“Ok”).update() Alexandre Bergel 11
  • 12. Import over Inheritance Import class refinement C widgetsCB NewWidgetsCB Component Component lookAndFeel paint() update() 4 3 paint() Button Button 2 1 new Button(“Ok”).update() new Button(“Ok”).update() Lookup of the update() method triggered within 1 enhWidgetsCB. Alexandre Bergel 12
  • 13. But update() calls paint() Import class refinement C widgetsCB NewWidgetsCB Component Component lookAndFeel paint() update() paint() 3 Button Button 2 1 new Button(“Ok”).update() new Button(“Ok”).update() Lookup of the paint() method triggered within 1 enhWidgetsCB Alexandre Bergel 13
  • 14. Old and New Clients at the Same Time Import class refinement C widgetsCB NewWidgetsCB Component Component lookAndFeel paint() update() paint() Button Button NewGUIAppCB OldGUIAppCB Button NewGUIApp Button OldGUIApp Alexandre Bergel 14
  • 15. Properties of Classboxes Minimal extension of the Java syntax (transitive import, • refine and original keywords). Refinements are confined to the classbox that define them • and to classboxes that import refined classes. Method redefinitions have precedence over previous • definitions. Classes can be refined without risk of breaking former • clients. Alexandre Bergel 15
  • 16. Swing Refactored as a Classbox AwtCB Component Container Button Window Frame SwingCB Component Window accessibleContext Frame component rootPane Button update() setLayout() add(Component) setRootPane() remove(Component) setContentPane() ... Alexandre Bergel 16
  • 17. Swing Refactoring 6500 lines of code refactored over 4 classes. • Inheritance defined in AwtCB is fully preserved in • SwingCB: – In SwingCB, every widget is a component (i.e., inherits from the extended AWT Component). – The property “a frame is a window” is true in SwingCB. Removed duplicated code: the refined Frame is 29 % • smaller than the original JFrame. • Explicit type checks like obj instanceof JComponent and (JComponent)obj are avoided. Alexandre Bergel 17
  • 18. Naive Implementation Based on source code manipulation. • The method call stack is introspected to determine the • right version of a method to be triggered. No cost for method additions, however slowdown of 1000 • times when calling a redefined method. However, much better results were obtained in Smalltalk. • 5 byte-codes are added to redefined methods (see our previous work). Alexandre Bergel 18
  • 19. Conclusion Classboxes delimit visibility of a change and avoid impacting • clients that should not be affected. Java is extended with two new keywords and transitive • import. Large case study showing how classboxes can be more • powerful than inheritance to support unanticipated changes. Performance could be improved by modifying the VM. • Alexandre Bergel 19
  • 20. We need an alternative to inheritance to support unanticipated changes! Alexandre Bergel: bergel@iam.unibe.ch google “classboxes” Alexandre Bergel 20
  • 22. A JWidget is not necessary a JComponent java.awt Component Button Container Window Frame javax.swing JComponent JWindow JFrame JButton Are not subclasses of JComponent Alexandre Bergel 22
  • 23. A JFrame is not a JWindow java.awt Component Button Container Window Frame javax.swing JComponent JWindow JFrame JButton Missing inheritance link between JFrame and JWindow Alexandre Bergel 23
  • 24. AWT and Swing Anomalies Features defined in JWindow are duplicated in JFrame (half • of JWindow code is in JFrame). The Swing design breaks the AWT inheritance relation: • – AWT: a Window is a Component – Swing: a JWindow is not a JComponent Need of explicit type checks and casts in Swing: • – For instance a JWindow needs to check if its elements are issued from Swing or not before rendering them – 82 type checks (instanceof) and 151 cast to (JComponent) Alexandre Bergel 24
  • 25. Method Call Stack Introspected NewWidgetsCB and WidgetsCB define the paint method: package WidgetsCB; public class Component { public void paint() { if (ClassboxInfo.methodVisible ( “NewWidgetsCB”, “Component”, “paint”)){ //Enhanced paint } if (ClassboxInfo.methodVisible ( “WidgetsCB”, “Component”, “paint”)){ //Original paint }}} Alexandre Bergel 25