SlideShare une entreprise Scribd logo
1  sur  25
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

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
 

Tendances (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
 

En vedette

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
 

En vedette (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
 

Similaire à 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
 

Similaire à 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
 

Plus de 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
 

Plus de 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
 

Dernier

(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
 
Annual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesAnnual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesKeppelCorporation
 
International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...ssuserf63bd7
 
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCRashishs7044
 
Financial-Statement-Analysis-of-Coca-cola-Company.pptx
Financial-Statement-Analysis-of-Coca-cola-Company.pptxFinancial-Statement-Analysis-of-Coca-cola-Company.pptx
Financial-Statement-Analysis-of-Coca-cola-Company.pptxsaniyaimamuddin
 
Memorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMMemorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMVoces Mineras
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Pereraictsugar
 
Innovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdfInnovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdfrichard876048
 
Investment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy CheruiyotInvestment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy Cheruiyotictsugar
 
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
 
8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCR8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket 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
 
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdfNewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdfKhaled Al Awadi
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menzaictsugar
 
Organizational Structure Running A Successful Business
Organizational Structure Running A Successful BusinessOrganizational Structure Running A Successful Business
Organizational Structure Running A Successful BusinessSeta Wicaksana
 
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
 
Market Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 EditionMarket Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 EditionMintel Group
 
Marketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent ChirchirMarketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent Chirchirictsugar
 
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607dollysharma2066
 

Dernier (20)

(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
 
Annual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesAnnual General Meeting Presentation Slides
Annual General Meeting Presentation Slides
 
International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...
 
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
 
Financial-Statement-Analysis-of-Coca-cola-Company.pptx
Financial-Statement-Analysis-of-Coca-cola-Company.pptxFinancial-Statement-Analysis-of-Coca-cola-Company.pptx
Financial-Statement-Analysis-of-Coca-cola-Company.pptx
 
Memorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMMemorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQM
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Perera
 
Innovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdfInnovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdf
 
Investment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy CheruiyotInvestment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy Cheruiyot
 
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
 
8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCR8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket 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
 
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdfNewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
 
Organizational Structure Running A Successful Business
Organizational Structure Running A Successful BusinessOrganizational Structure Running A Successful Business
Organizational Structure Running A Successful Business
 
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
 
Market Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 EditionMarket Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 Edition
 
Marketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent ChirchirMarketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent Chirchir
 
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
 
Call Us ➥9319373153▻Call Girls In North Goa
Call Us ➥9319373153▻Call Girls In North GoaCall Us ➥9319373153▻Call Girls In North Goa
Call Us ➥9319373153▻Call Girls In North Goa
 

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