SlideShare uma empresa Scribd logo
1 de 36
Baixar para ler offline
!quot;#$




Modularity beyond
  inheritance
      Alexandre Bergel
     RMoD team, INRIA,
         Lille, France
    alexandre@bergel.eu
Goal of this lecture



 •   To introduce research problems related to class-inheritance

 •   Present 2 state-of-the-art research topics related to class
     inheritance
Sources & references
 •   Wirfs-Brock & McKean, Object Design — Roles,
     Responsibilities and Collaborations, 2003.

 •   Alexandre Bergel, Stéphane Ducasse, and Oscar Nierstrasz,
     Classbox/J: Controlling the Scope of Change in Java, OOPSLA'05

 •   Damien Cassou, Stéphane Ducasse and Roel Wuyts, Traits at
     Work: the design of a new trait-based stream library, In Journal
     of Computer Languages, Systems and Structures, Elsevier,
     2008

 •   Stephane Ducasse, Roel Wuts, Alexandre Bergel, and Oscar
     Nierstrasz, User-Changeable Visibility: Resolving Unanticipated
     Name Clashes in Traits, OOPSLA'07
Outline


1. Inheritance
2. Classboxes: evolving behavior
3. Traits: composing behavior
4. Concluding words
Inheritance


 •   Inheritance in object-oriented programming languages is a
     mechanism to:

     -   derive new subclasses from existing classes

     -   where subclasses inherit all the features from their
         parent(s)

     -   and may selectively override the implementation of some
         features.
Inheritance mechanisms

•   OO languages realize inheritance in different ways:

    -   self: dynamically access subclass methods

    -   super: statically access overridden, inherited methods

    -   multiple inheritance: inherit features from multiple superclasses

    -   abstract classes: partially defined classes (to inherit from only)

    -   mixins: build classes from partial sets of features

    -   interfaces: specify method argument and return types

    -   subtyping: guarantees that subclass instances can be substituted
Classboxes for evolution


 I. Problem: AWT and Swing anomalies
 II. Model: Classbox/J
 III. Solution: Swing as a classbox
 IV. Ongoing work: general scoping mechanism (not presented)
Presentation of AWT
 java.awt

                                   Component


                                    Container        Button
                    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)
Broken Inheritance in Swing
 java.awt

                        Component


                        Container    Button
              Window
   Frame

javax.swing

                        JComponent
   JFrame     JWindow
                                     JButton
Problem: Code Duplication
                                                         Code Duplication
 java.awt

                                         Component


                                          Container      Button
                       Window
    Frame

javax.swing

                                         JComponent
    JFrame             JWindow
                                        accessibleCont
accessibleContext   accessibleContext   ext
                                        update()         JButton
rootPane            rootPane
update()            update()
setLayout()         setLayout()
...                 ...
Problem: explicit type operation
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();
     }
  }}
Alternative to inheritance

•   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 an alternative to inheritance to support
    unanticipated changes.
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
Swing Refactored as a Classbox
  AwtCB

                                         Component


                                   Container                 Button
                     Window
      Frame

 javax.swing

                                          JComponent
     JFrame             JWindow
                                         accessibleContext
 accessibleContext   accessibleContext   ext
                                         update()            JButton
 rootPane            rootPane
 update()            update()
 setLayout()         setLayout()
 ...                 ...
Swing Refactored as a Classbox
 AwtCB

                                    Component


                               Container              Button
              Window
    Frame

 SwingCB

                                    Component
    Frame      Window             accessibleContext
                                  component
            rootPane
            setLayout()
                                  update()
                                  add(Component)      Button
            setRootPane()         remove(Component)
            setContentPane()
            ...
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.
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.
Traits


 I. Problem: Stream in Squeak anomalies
 II. Model: Traits
 III. Solution: Refactoring with Traits
 IV. Ongoing work: Pure trait language (not presented)
Stream in Squeak



 •   Example of a library that has been in use for almost 20
     years

 •   Contains many flaws in its conception
Stream in Squeak
                                                                 FileStream
                                                               rwmode
                                               WriteStream
                Positionable                                   name
                                              writeLimit
                   Stream                                      fileID
                                              contents
               collection                                      buffer1
                                              flush
      Stream   position                                        atEnd
                                              next
atEnd          readLimit                                       close
                                              nextPut:
close          atEnd                                           flush
                                              nextPutAll:
contents       contents                                        fullName
                                              position:
do:            isEmpty                                         next
                                              reset
flush           next:                                           next:
                                              setToEnd
next           peek                                            nextPut:
                                              size
next:          position                                        nextPutAll:
                                              space
next:put:      position:        ReadStream                     peek
                                              cr
nextPut:       reset           next                            position
nextPutAll:    setToEnd        next:                           position:
upToEnd        skip:           nextPut:      ReadWriteStream   reset
               skipTo:         size          close             setToEnd
               upTo:           upTo:         contents          size
               upToEnd         upToEnd       next              skip:
                                             next:             upTo:
                                                               upToEnd
Methods too high
                                                                 FileStream
                                                               rwmode
                                               WriteStream
                Positionable                                   name
                                              writeLimit
                   Stream                                      fileID
                                              contents
               collection                                      buffer1
                                              flush
      Stream   position                                        atEnd
                                              next
atEnd          readLimit                                       close
                                              nextPut:
close          atEnd                                           flush
                                              nextPutAll:
contents       contents                                        fullName
                                              position:
do:            isEmpty                                         next
                                              reset
flush           next:                                           next:
                                              setToEnd
next           peek                                            nextPut:
                                              size
next:          position                                        nextPutAll:
                                              space
next:put:      position:        ReadStream                     peek
                                              cr
nextPut:       reset           next                            position
nextPutAll:    setToEnd        next:                           position:
upToEnd        skip:           nextPut:      ReadWriteStream   reset
               skipTo:         size          close             setToEnd
               upTo:           upTo:         contents          size
               upToEnd         upToEnd       next              skip:
nextPutAll: aCollection                      next:             upTo:
                                                               upToEnd
  aCollection do: [:v| self nextPut: v].
  ^ aCollection
Methods too high


•   The nextPut: method defined in Stream allows for element
    addition

•   The ReadStream class is read-only

•   It therefore needs to “cancel” this method by redefining it
    and throwing an exception
Unused state
                                                                 FileStream
                                                               rwmode
                                               WriteStream
                Positionable                                   name
                                              writeLimit
                   Stream                                      fileID
                                              contents
               collection                                      buffer1
                                              flush
      Stream   position                                        atEnd
                                              next
atEnd          readLimit                                       close
                                              nextPut:
close          atEnd                                           flush
                                              nextPutAll:
contents       contents                                        fullName
                                              position:
do:            isEmpty                                         next
                                              reset
flush           next:                                           next:
                                              setToEnd
next           peek                                            nextPut:
                                              size
next:          position                                        nextPutAll:
                                              space
next:put:      position:        ReadStream                     peek
                                              cr
nextPut:       reset           next                            position
nextPutAll:    setToEnd        next:                           position:
upToEnd        skip:           nextPut:      ReadWriteStream   reset
               skipTo:         size          close             setToEnd
               upTo:           upTo:         contents          size
               upToEnd         upToEnd       next              skip:
                                             next:             upTo:
                                                               upToEnd
Unused state



•   State defined in the super classes are becoming irrelevant in
    subclasses

•   FileStream does not use inherited variables
Multiple inheritance simulation
                                                                 FileStream
                                                               rwmode
                                               WriteStream
                Positionable                                   name
                                              writeLimit
                   Stream                                      fileID
                                              contents
               collection                                      buffer1
                                              flush
      Stream   position                                        atEnd
                                              next
atEnd          readLimit                                       close
                                              nextPut:
close          atEnd                                           flush
                                              nextPutAll:
contents       contents                                        fullName
                                              position:
do:            isEmpty                                         next
                                              reset
flush           next:                                           next:
                                              setToEnd
next           peek                                            nextPut:
                                              size
next:          position                                        nextPutAll:
                                              space
next:put:      position:        ReadStream                     peek
                                              cr
nextPut:       reset           next                            position
nextPutAll:    setToEnd        next:                           position:
upToEnd        skip:           nextPut:      ReadWriteStream   reset
               skipTo:         size          close             setToEnd
               upTo:           upTo:         contents          size
               upToEnd         upToEnd       next              skip:
                                             next:             upTo:
                                                               upToEnd
Multiple inheritance




 •   Methods are duplicated among different class hierarchies
Class responsibilities



 •   Too many responsibilities for classes

     -   object factories

     -   group methods when subclassing
         `
Class schizophrenia?



 •   Too many responsibilities for classes

     -   object factories => need for completeness

     -   group methods when subclassing => need to incorporate
         incomplete fragments
Traits

 •   Traits are parameterized behaviors
     -  traits provide a set of methods
     -  traits require a set of methods
     -  traits are purely behavioral

                           TCircle
                      area       radius
                      bounds     radius:
                      diameter   center
                      hash       center:
                      ...
Class = Superclass + State + Traits + Glue Methods




    •   Traits are the behavioral building blocks of classes

                                                           Generic properties
                          Object
                                                                 TColor

                                                               TRectangle
             Component               Geometrical
                                                                    ...

  RectangleWidget                              RectangleShape
x1, y1, x2, y2              TColor        point1, point2
setX1(...)                                setX1(...)
setY1(...)                TRectangle      setY1(...)
Composition rules

 Class methods take precedence over trait methods

  ColoredCircle                   ColoredCircle

                  TCircle                         TCircle
                                  draw       draw
              draw
                                             radius
              radius

                    TColor                          TColor
              hue                             hue
              rgb                             rgb
Conflicts are explicitly resolved

 •     Override the conflict with a glue method
     -   Aliases provide access to the conflicting methods
 •     Avoid the conflict
     -   Exclude the conflicting method from one trait



 ColoredCircle                           ColoredCircle
                   TCircle                                  TCircle
             hash -> circleHash                    hash -> circleHash
hash
                   TColor                                   TColor
             hash -> colorHash                     hash
Flattening property

Structured view                             Flat view
     Object                 equivalent         Object


  ColoredCircle                           ColoredCircle

                  TCircle
 draw      draw                          draw
           radius                        radius

                  TColor
           hue                           hue
           rgb                           rgb
Stream revisited
  Core                                                   TStream
                                                  binary
                                                  close
                                                  closed
                                                  isBinary
                                                  isClosed
                                                  isStream

               TGettableStream
 do:                    atEnd                   TPositionableStream            TPuttableStream
 nextMatchFor:          next                    atEnd        position       nextPutAll: nextPut:
 next:                  peek                    atStart      setPosition:   next:put:
 peekFor:               outputCollectionClass   back         size           print:
 skip:                                          close                       flush
 skipTo:                                        isEmpty
 upTo:                                          position:
 upToEnd                                        reset
 upToElementSatisfying:                         setToEnd


                                 @ {#basicBack->#back}

                        TGettablePositionableStream               TPuttablePositionableStream
                        back                                     writeBack
                        backUpTo:
                        match:
                        nextDelimited:
                        skip:
Concluding words



•   Hard topic where proving a better solution requires a
    significant effort

•   Other hot topics: Virtual classes, Nested inheritance,
    Selector namespaces
2008 Sccc Inheritance

Mais conteúdo relacionado

Mais procurados

What is new and cool j2se & java
What is new and cool j2se & javaWhat is new and cool j2se & java
What is new and cool j2se & javaEugene Bogaart
 
Have Your Cake and Eat It Too: Meta-Programming Techniques for Java
Have Your Cake and Eat It Too: Meta-Programming Techniques for JavaHave Your Cake and Eat It Too: Meta-Programming Techniques for Java
Have Your Cake and Eat It Too: Meta-Programming Techniques for JavaHoward Lewis Ship
 
Java Future S Ritter
Java Future S RitterJava Future S Ritter
Java Future S Rittercatherinewall
 
クラウド・アプリケーション・アーキテクチャ
クラウド・アプリケーション・アーキテクチャクラウド・アプリケーション・アーキテクチャ
クラウド・アプリケーション・アーキテクチャTomoharu ASAMI
 
Java Concurrency Quick Guide
Java Concurrency Quick GuideJava Concurrency Quick Guide
Java Concurrency Quick GuideAnton Shchastnyi
 
Ruby vs Java
Ruby vs JavaRuby vs Java
Ruby vs JavaBelighted
 
Let'swift "Concurrency in swift"
Let'swift "Concurrency in swift"Let'swift "Concurrency in swift"
Let'swift "Concurrency in swift"Hyuk Hur
 
WebGL - 3D in your Browser
WebGL - 3D in your BrowserWebGL - 3D in your Browser
WebGL - 3D in your BrowserPhil Reither
 
Develop Ruby Applications Fast | TubroRuby
Develop Ruby Applications Fast | TubroRubyDevelop Ruby Applications Fast | TubroRuby
Develop Ruby Applications Fast | TubroRubyMichael Findling
 
Java Course 3: OOP
Java Course 3: OOPJava Course 3: OOP
Java Course 3: OOPAnton Keks
 
Java Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & EncodingsJava Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & EncodingsAnton Keks
 
Java Course 15: Ant, Scripting, Spring, Hibernate
Java Course 15: Ant, Scripting, Spring, HibernateJava Course 15: Ant, Scripting, Spring, Hibernate
Java Course 15: Ant, Scripting, Spring, HibernateAnton Keks
 
Java Beans Unit 4(part 2)
Java Beans Unit 4(part 2)Java Beans Unit 4(part 2)
Java Beans Unit 4(part 2)SURBHI SAROHA
 

Mais procurados (17)

BeJUG JavaFx In Practice
BeJUG JavaFx In PracticeBeJUG JavaFx In Practice
BeJUG JavaFx In Practice
 
What is new and cool j2se & java
What is new and cool j2se & javaWhat is new and cool j2se & java
What is new and cool j2se & java
 
Have Your Cake and Eat It Too: Meta-Programming Techniques for Java
Have Your Cake and Eat It Too: Meta-Programming Techniques for JavaHave Your Cake and Eat It Too: Meta-Programming Techniques for Java
Have Your Cake and Eat It Too: Meta-Programming Techniques for Java
 
Core java
Core javaCore java
Core java
 
Java Future S Ritter
Java Future S RitterJava Future S Ritter
Java Future S Ritter
 
WCET analyse af java bytecode af Kasper Søe Luckow, AAU
WCET analyse af java bytecode af Kasper Søe Luckow, AAUWCET analyse af java bytecode af Kasper Søe Luckow, AAU
WCET analyse af java bytecode af Kasper Søe Luckow, AAU
 
クラウド・アプリケーション・アーキテクチャ
クラウド・アプリケーション・アーキテクチャクラウド・アプリケーション・アーキテクチャ
クラウド・アプリケーション・アーキテクチャ
 
Java Concurrency Quick Guide
Java Concurrency Quick GuideJava Concurrency Quick Guide
Java Concurrency Quick Guide
 
Ruby vs Java
Ruby vs JavaRuby vs Java
Ruby vs Java
 
Let'swift "Concurrency in swift"
Let'swift "Concurrency in swift"Let'swift "Concurrency in swift"
Let'swift "Concurrency in swift"
 
Cnc scala-presentation
Cnc scala-presentationCnc scala-presentation
Cnc scala-presentation
 
WebGL - 3D in your Browser
WebGL - 3D in your BrowserWebGL - 3D in your Browser
WebGL - 3D in your Browser
 
Develop Ruby Applications Fast | TubroRuby
Develop Ruby Applications Fast | TubroRubyDevelop Ruby Applications Fast | TubroRuby
Develop Ruby Applications Fast | TubroRuby
 
Java Course 3: OOP
Java Course 3: OOPJava Course 3: OOP
Java Course 3: OOP
 
Java Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & EncodingsJava Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & Encodings
 
Java Course 15: Ant, Scripting, Spring, Hibernate
Java Course 15: Ant, Scripting, Spring, HibernateJava Course 15: Ant, Scripting, Spring, Hibernate
Java Course 15: Ant, Scripting, Spring, Hibernate
 
Java Beans Unit 4(part 2)
Java Beans Unit 4(part 2)Java Beans Unit 4(part 2)
Java Beans Unit 4(part 2)
 

Destaque

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
 
Test beautycleanness
Test beautycleannessTest beautycleanness
Test beautycleannessbergel
 
Multi dimensional profiling
Multi dimensional profilingMulti dimensional profiling
Multi dimensional profilingbergel
 
2005 Oopsla Classboxj
2005 Oopsla Classboxj2005 Oopsla Classboxj
2005 Oopsla Classboxjbergel
 
2008 Sccc Smalltalk
2008 Sccc Smalltalk2008 Sccc Smalltalk
2008 Sccc Smalltalkbergel
 

Destaque (7)

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
 
Test beautycleanness
Test beautycleannessTest beautycleanness
Test beautycleanness
 
Multi dimensional profiling
Multi dimensional profilingMulti dimensional profiling
Multi dimensional profiling
 
2005 Oopsla Classboxj
2005 Oopsla Classboxj2005 Oopsla Classboxj
2005 Oopsla Classboxj
 
2008 Sccc Smalltalk
2008 Sccc Smalltalk2008 Sccc Smalltalk
2008 Sccc Smalltalk
 

Semelhante a 2008 Sccc Inheritance

Fabric.js @ Falsy Values
Fabric.js @ Falsy ValuesFabric.js @ Falsy Values
Fabric.js @ Falsy ValuesJuriy Zaytsev
 
JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesCharles Nutter
 
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012Anton Arhipov
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionGanesh Samarthyam
 
Jalimo Slides Linuxtag2007 (English)
Jalimo Slides Linuxtag2007 (English)Jalimo Slides Linuxtag2007 (English)
Jalimo Slides Linuxtag2007 (English)smancke
 
TWaver Web Performance Report
TWaver Web Performance ReportTWaver Web Performance Report
TWaver Web Performance Report253725291
 
Deep Dive into Backbone.js Internals + Underscore.js
Deep Dive into Backbone.js Internals + Underscore.jsDeep Dive into Backbone.js Internals + Underscore.js
Deep Dive into Backbone.js Internals + Underscore.jsMauvis Ledford
 
The State of Managed Runtimes 2013, by Attila Szegedi
The State of Managed Runtimes 2013, by Attila SzegediThe State of Managed Runtimes 2013, by Attila Szegedi
The State of Managed Runtimes 2013, by Attila SzegediZeroTurnaround
 
WebSphere Message Broker v6.x Overview - 2008-01-09
WebSphere Message Broker v6.x Overview - 2008-01-09WebSphere Message Broker v6.x Overview - 2008-01-09
WebSphere Message Broker v6.x Overview - 2008-01-09Mårten Gustafson
 
Rapid java application development @ JUG.ru 25.02.2012
Rapid java application development @ JUG.ru 25.02.2012Rapid java application development @ JUG.ru 25.02.2012
Rapid java application development @ JUG.ru 25.02.2012Anton Arhipov
 
Shiksharth com java_topics
Shiksharth com java_topicsShiksharth com java_topics
Shiksharth com java_topicsRajesh Verma
 
Android Bootstrap
Android BootstrapAndroid Bootstrap
Android Bootstrapdonnfelker
 
MODEL OF A PROGRAM AS MULTITHREADED STOCHASTIC AUTOMATON AND ITS EQUIVALENT T...
MODEL OF A PROGRAM AS MULTITHREADED STOCHASTIC AUTOMATON AND ITS EQUIVALENT T...MODEL OF A PROGRAM AS MULTITHREADED STOCHASTIC AUTOMATON AND ITS EQUIVALENT T...
MODEL OF A PROGRAM AS MULTITHREADED STOCHASTIC AUTOMATON AND ITS EQUIVALENT T...Sergey Staroletov
 
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Paul King
 
Logic-based program transformation in symbiosis with Eclipse
Logic-based program transformation in symbiosis with EclipseLogic-based program transformation in symbiosis with Eclipse
Logic-based program transformation in symbiosis with EclipseCoen De Roover
 
It pro dev_birbilis_20101127_en
It pro dev_birbilis_20101127_enIt pro dev_birbilis_20101127_en
It pro dev_birbilis_20101127_enGeorge Birbilis
 

Semelhante a 2008 Sccc Inheritance (20)

Jvm internals
Jvm internalsJvm internals
Jvm internals
 
Fabric.js @ Falsy Values
Fabric.js @ Falsy ValuesFabric.js @ Falsy Values
Fabric.js @ Falsy Values
 
JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for Dummies
 
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - Description
 
Jalimo Slides Linuxtag2007 (English)
Jalimo Slides Linuxtag2007 (English)Jalimo Slides Linuxtag2007 (English)
Jalimo Slides Linuxtag2007 (English)
 
TWaver Web Performance Report
TWaver Web Performance ReportTWaver Web Performance Report
TWaver Web Performance Report
 
Deep Dive into Backbone.js Internals + Underscore.js
Deep Dive into Backbone.js Internals + Underscore.jsDeep Dive into Backbone.js Internals + Underscore.js
Deep Dive into Backbone.js Internals + Underscore.js
 
The State of Managed Runtimes 2013, by Attila Szegedi
The State of Managed Runtimes 2013, by Attila SzegediThe State of Managed Runtimes 2013, by Attila Szegedi
The State of Managed Runtimes 2013, by Attila Szegedi
 
WebSphere Message Broker v6.x Overview - 2008-01-09
WebSphere Message Broker v6.x Overview - 2008-01-09WebSphere Message Broker v6.x Overview - 2008-01-09
WebSphere Message Broker v6.x Overview - 2008-01-09
 
basic_java.ppt
basic_java.pptbasic_java.ppt
basic_java.ppt
 
Rapid java application development @ JUG.ru 25.02.2012
Rapid java application development @ JUG.ru 25.02.2012Rapid java application development @ JUG.ru 25.02.2012
Rapid java application development @ JUG.ru 25.02.2012
 
Shiksharth com java_topics
Shiksharth com java_topicsShiksharth com java_topics
Shiksharth com java_topics
 
Android Bootstrap
Android BootstrapAndroid Bootstrap
Android Bootstrap
 
MODEL OF A PROGRAM AS MULTITHREADED STOCHASTIC AUTOMATON AND ITS EQUIVALENT T...
MODEL OF A PROGRAM AS MULTITHREADED STOCHASTIC AUTOMATON AND ITS EQUIVALENT T...MODEL OF A PROGRAM AS MULTITHREADED STOCHASTIC AUTOMATON AND ITS EQUIVALENT T...
MODEL OF A PROGRAM AS MULTITHREADED STOCHASTIC AUTOMATON AND ITS EQUIVALENT T...
 
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
 
Swing
SwingSwing
Swing
 
Swing
SwingSwing
Swing
 
Logic-based program transformation in symbiosis with Eclipse
Logic-based program transformation in symbiosis with EclipseLogic-based program transformation in symbiosis with Eclipse
Logic-based program transformation in symbiosis with Eclipse
 
It pro dev_birbilis_20101127_en
It pro dev_birbilis_20101127_enIt pro dev_birbilis_20101127_en
It pro dev_birbilis_20101127_en
 

Mais 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
 

Mais 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
 

Último

Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxElton John Embodo
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxRosabel UA
 

Último (20)

Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptx
 

2008 Sccc Inheritance

  • 1. !quot;#$ Modularity beyond inheritance Alexandre Bergel RMoD team, INRIA, Lille, France alexandre@bergel.eu
  • 2. Goal of this lecture • To introduce research problems related to class-inheritance • Present 2 state-of-the-art research topics related to class inheritance
  • 3. Sources & references • Wirfs-Brock & McKean, Object Design — Roles, Responsibilities and Collaborations, 2003. • Alexandre Bergel, Stéphane Ducasse, and Oscar Nierstrasz, Classbox/J: Controlling the Scope of Change in Java, OOPSLA'05 • Damien Cassou, Stéphane Ducasse and Roel Wuyts, Traits at Work: the design of a new trait-based stream library, In Journal of Computer Languages, Systems and Structures, Elsevier, 2008 • Stephane Ducasse, Roel Wuts, Alexandre Bergel, and Oscar Nierstrasz, User-Changeable Visibility: Resolving Unanticipated Name Clashes in Traits, OOPSLA'07
  • 4. Outline 1. Inheritance 2. Classboxes: evolving behavior 3. Traits: composing behavior 4. Concluding words
  • 5. Inheritance • Inheritance in object-oriented programming languages is a mechanism to: - derive new subclasses from existing classes - where subclasses inherit all the features from their parent(s) - and may selectively override the implementation of some features.
  • 6. Inheritance mechanisms • OO languages realize inheritance in different ways: - self: dynamically access subclass methods - super: statically access overridden, inherited methods - multiple inheritance: inherit features from multiple superclasses - abstract classes: partially defined classes (to inherit from only) - mixins: build classes from partial sets of features - interfaces: specify method argument and return types - subtyping: guarantees that subclass instances can be substituted
  • 7. Classboxes for evolution I. Problem: AWT and Swing anomalies II. Model: Classbox/J III. Solution: Swing as a classbox IV. Ongoing work: general scoping mechanism (not presented)
  • 8. Presentation of AWT java.awt Component Container Button 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)
  • 9. Broken Inheritance in Swing java.awt Component Container Button Window Frame javax.swing JComponent JFrame JWindow JButton
  • 10. Problem: Code Duplication Code Duplication java.awt Component Container Button Window Frame javax.swing JComponent JFrame JWindow accessibleCont accessibleContext accessibleContext ext update() JButton rootPane rootPane update() update() setLayout() setLayout() ... ...
  • 11. Problem: explicit type operation 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(); } }}
  • 12. Alternative to inheritance • 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 an alternative to inheritance to support unanticipated changes.
  • 13. 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
  • 14. Swing Refactored as a Classbox AwtCB Component Container Button Window Frame javax.swing JComponent JFrame JWindow accessibleContext accessibleContext accessibleContext ext update() JButton rootPane rootPane update() update() setLayout() setLayout() ... ...
  • 15. Swing Refactored as a Classbox AwtCB Component Container Button Window Frame SwingCB Component Frame Window accessibleContext component rootPane setLayout() update() add(Component) Button setRootPane() remove(Component) setContentPane() ...
  • 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.
  • 17. 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.
  • 18. Traits I. Problem: Stream in Squeak anomalies II. Model: Traits III. Solution: Refactoring with Traits IV. Ongoing work: Pure trait language (not presented)
  • 19. Stream in Squeak • Example of a library that has been in use for almost 20 years • Contains many flaws in its conception
  • 20. Stream in Squeak FileStream rwmode WriteStream Positionable name writeLimit Stream fileID contents collection buffer1 flush Stream position atEnd next atEnd readLimit close nextPut: close atEnd flush nextPutAll: contents contents fullName position: do: isEmpty next reset flush next: next: setToEnd next peek nextPut: size next: position nextPutAll: space next:put: position: ReadStream peek cr nextPut: reset next position nextPutAll: setToEnd next: position: upToEnd skip: nextPut: ReadWriteStream reset skipTo: size close setToEnd upTo: upTo: contents size upToEnd upToEnd next skip: next: upTo: upToEnd
  • 21. Methods too high FileStream rwmode WriteStream Positionable name writeLimit Stream fileID contents collection buffer1 flush Stream position atEnd next atEnd readLimit close nextPut: close atEnd flush nextPutAll: contents contents fullName position: do: isEmpty next reset flush next: next: setToEnd next peek nextPut: size next: position nextPutAll: space next:put: position: ReadStream peek cr nextPut: reset next position nextPutAll: setToEnd next: position: upToEnd skip: nextPut: ReadWriteStream reset skipTo: size close setToEnd upTo: upTo: contents size upToEnd upToEnd next skip: nextPutAll: aCollection next: upTo: upToEnd aCollection do: [:v| self nextPut: v]. ^ aCollection
  • 22. Methods too high • The nextPut: method defined in Stream allows for element addition • The ReadStream class is read-only • It therefore needs to “cancel” this method by redefining it and throwing an exception
  • 23. Unused state FileStream rwmode WriteStream Positionable name writeLimit Stream fileID contents collection buffer1 flush Stream position atEnd next atEnd readLimit close nextPut: close atEnd flush nextPutAll: contents contents fullName position: do: isEmpty next reset flush next: next: setToEnd next peek nextPut: size next: position nextPutAll: space next:put: position: ReadStream peek cr nextPut: reset next position nextPutAll: setToEnd next: position: upToEnd skip: nextPut: ReadWriteStream reset skipTo: size close setToEnd upTo: upTo: contents size upToEnd upToEnd next skip: next: upTo: upToEnd
  • 24. Unused state • State defined in the super classes are becoming irrelevant in subclasses • FileStream does not use inherited variables
  • 25. Multiple inheritance simulation FileStream rwmode WriteStream Positionable name writeLimit Stream fileID contents collection buffer1 flush Stream position atEnd next atEnd readLimit close nextPut: close atEnd flush nextPutAll: contents contents fullName position: do: isEmpty next reset flush next: next: setToEnd next peek nextPut: size next: position nextPutAll: space next:put: position: ReadStream peek cr nextPut: reset next position nextPutAll: setToEnd next: position: upToEnd skip: nextPut: ReadWriteStream reset skipTo: size close setToEnd upTo: upTo: contents size upToEnd upToEnd next skip: next: upTo: upToEnd
  • 26. Multiple inheritance • Methods are duplicated among different class hierarchies
  • 27. Class responsibilities • Too many responsibilities for classes - object factories - group methods when subclassing `
  • 28. Class schizophrenia? • Too many responsibilities for classes - object factories => need for completeness - group methods when subclassing => need to incorporate incomplete fragments
  • 29. Traits • Traits are parameterized behaviors - traits provide a set of methods - traits require a set of methods - traits are purely behavioral TCircle area radius bounds radius: diameter center hash center: ...
  • 30. Class = Superclass + State + Traits + Glue Methods • Traits are the behavioral building blocks of classes Generic properties Object TColor TRectangle Component Geometrical ... RectangleWidget RectangleShape x1, y1, x2, y2 TColor point1, point2 setX1(...) setX1(...) setY1(...) TRectangle setY1(...)
  • 31. Composition rules Class methods take precedence over trait methods ColoredCircle ColoredCircle TCircle TCircle draw draw draw radius radius TColor TColor hue hue rgb rgb
  • 32. Conflicts are explicitly resolved • Override the conflict with a glue method - Aliases provide access to the conflicting methods • Avoid the conflict - Exclude the conflicting method from one trait ColoredCircle ColoredCircle TCircle TCircle hash -> circleHash hash -> circleHash hash TColor TColor hash -> colorHash hash
  • 33. Flattening property Structured view Flat view Object equivalent Object ColoredCircle ColoredCircle TCircle draw draw draw radius radius TColor hue hue rgb rgb
  • 34. Stream revisited Core TStream binary close closed isBinary isClosed isStream TGettableStream do: atEnd TPositionableStream TPuttableStream nextMatchFor: next atEnd position nextPutAll: nextPut: next: peek atStart setPosition: next:put: peekFor: outputCollectionClass back size print: skip: close flush skipTo: isEmpty upTo: position: upToEnd reset upToElementSatisfying: setToEnd @ {#basicBack->#back} TGettablePositionableStream TPuttablePositionableStream back writeBack backUpTo: match: nextDelimited: skip:
  • 35. Concluding words • Hard topic where proving a better solution requires a significant effort • Other hot topics: Virtual classes, Nested inheritance, Selector namespaces