SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...lizamodels9
 
Future Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted VersionFuture Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted VersionMintel Group
 
MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?Olivia Kresic
 
Annual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesAnnual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesKeppelCorporation
 
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCRashishs7044
 
Innovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdfInnovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdfrichard876048
 
Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Riya Pathan
 
Keppel Ltd. 1Q 2024 Business Update Presentation Slides
Keppel Ltd. 1Q 2024 Business Update  Presentation SlidesKeppel Ltd. 1Q 2024 Business Update  Presentation Slides
Keppel Ltd. 1Q 2024 Business Update Presentation SlidesKeppelCorporation
 
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...lizamodels9
 
Buy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail AccountsBuy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail AccountsBuy Verified Accounts
 
Intro to BCG's Carbon Emissions Benchmark_vF.pdf
Intro to BCG's Carbon Emissions Benchmark_vF.pdfIntro to BCG's Carbon Emissions Benchmark_vF.pdf
Intro to BCG's Carbon Emissions Benchmark_vF.pdfpollardmorgan
 
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort ServiceCall US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Servicecallgirls2057
 
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCRashishs7044
 
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607dollysharma2066
 
8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCR8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCRashishs7044
 
Kenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby AfricaKenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby Africaictsugar
 
Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03DallasHaselhorst
 
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...lizamodels9
 
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCRashishs7044
 

Kürzlich hochgeladen (20)

Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...
 
Future Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted VersionFuture Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted Version
 
MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?
 
Annual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesAnnual General Meeting Presentation Slides
Annual General Meeting Presentation Slides
 
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
 
Innovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdfInnovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdf
 
Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737
 
Keppel Ltd. 1Q 2024 Business Update Presentation Slides
Keppel Ltd. 1Q 2024 Business Update  Presentation SlidesKeppel Ltd. 1Q 2024 Business Update  Presentation Slides
Keppel Ltd. 1Q 2024 Business Update Presentation Slides
 
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
 
Buy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail AccountsBuy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail Accounts
 
Intro to BCG's Carbon Emissions Benchmark_vF.pdf
Intro to BCG's Carbon Emissions Benchmark_vF.pdfIntro to BCG's Carbon Emissions Benchmark_vF.pdf
Intro to BCG's Carbon Emissions Benchmark_vF.pdf
 
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort ServiceCall US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
 
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
 
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
 
8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCR8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCR
 
Kenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby AfricaKenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby Africa
 
Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03
 
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
 
Japan IT Week 2024 Brochure by 47Billion (English)
Japan IT Week 2024 Brochure by 47Billion (English)Japan IT Week 2024 Brochure by 47Billion (English)
Japan IT Week 2024 Brochure by 47Billion (English)
 
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
 

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