method shells avoiding conflicts on destructive class
play

+ Method Shells: avoiding conflicts on destructive class - PowerPoint PPT Presentation

+ Method Shells: avoiding conflicts on destructive class extensions by implicit context switches ! Wakana Takeshita and Shigeru Chiba The University of Tokyo ! + Application and Software ! 2


  1. + Method ¡Shells: ¡avoiding ¡conflicts ¡on ¡destructive ¡ class ¡extensions ¡by ¡implicit ¡context ¡switches ! Wakana Takeshita and Shigeru Chiba The University of Tokyo !

  2. + Application ¡and ¡Software ! 2 ! l 1 : HTML renderer ! n Modern applications are built on top of existing libraries n but often not as they l 2 : web browser ! l 3 : HTML viewer ! are n Need to modify the libraries Application !

  3. Mechanisms ¡for ¡modular ¡customization ! + 3 ! n Ruby’s openclass l 1 : HTML renderer class Webpage{ n AspectJ’s aspect void popup(HTML text){ // show a popup window n [‘01 Kiczales et al.] } ! void onClick(Mouse m){ URL url = m.getURL(); n GluonJ popup(url); … n [’10 Chiba et al.] } ! } n Classboxes Redefine ! n [’10 Bergel et al.] n etc… l 2 : web browser ! revise Webpage{ Example in GluonJ ! void popup(HTML text){ warning(“disabled”); } ! } !

  4. + Destructive ¡Class ¡Extensions ! 4 ! l 1 : HTML renderer n A mechanism for writing original file ! only differences in a separate source file original without rewriting existing definitions ! code ! n for adding new methods to existing classes, and Redefine ! n for redefining existing methods l 2 : web browser ! n Modularization of another file ! modifications Destructive n Dividing the work ! class extensions ! !

  5. + Problem ¡Caused ¡by ¡Conflicts ¡of ¡ 5 ! Modifications ! void popup(HTML text){ // show a popup window } ! l 1 : HTML renderer ! void popup(HTML text ){ warning(“disabled”); } ! Which a l 3 : HTML viewer ! definition is l 2 : web browser ! applied? ! void check(File f) { … new Webpage().popup(…); …} ! Application ! Application !

  6. + Solution ! void popup(HTML text){ 6 ! // show a popup window } ! l 1 : HTML renderer ! void popup(HTML text){ warning(“disabled”); } ! l 3 : HTML viewer ! l 2 : web browser ! void check(File f) { … new Webpage().popup(…); Application ! …} ! n Switch the applied destructive class extensions depending on the program’s context n How to define the context? n by using two types of import n one context = a set of boxes connected by arrows ! !

  7. + Solution ! void popup(HTML text){ 7 ! // show a popup window } ! l 1 : HTML renderer ! void popup(HTML text){ warning(“disabled”); } ! l 3 : HTML viewer ! l 2 : web browser ! void check(File f) { … new Webpage().popup(…); Application ! …} ! n Switch the applied destructive class extensions depending on the program’s context n How to define the context? n by using two types of import n one context = a set of boxes connected by arrows ! !

  8. + Proposal: ¡Method ¡Shells ! 8 ! n a module system for avoiding conflicts by switching a set of revisers to fit execution contexts during runtime. n The context is defined by two declarations n Link : for switching the contexts n Include : for sharing the contexts. ! l 2 : webBrowser ! methodshell browser ; n module: methodshell //include and link declarations n contains two include renderer; declarations, class //declarations declarations and revise Webpage{ destructive class void popup(HTML text){ warning(“disabled”); extensions ! } ! } !

  9. + Include ¡declarations ! 9 ! n Used when to revise other methodshells n Share the same context l 1 : HTML renderer methodshell renderer ; class Webpage{ include void popup(HTML text){ link // show a popup window } ! context1 void onClick(Mouse m){ context2 … popup(url); … } ! } l 3 : HTML viewer ! l 3 : HTML viewer ! methodshell viewer ; methodshell viewer ; l 2 : webBrowser ! include renderer; include renderer; methodshell browser ; class Viewer{ class Viewer{ void check(File f) { void check(File f) { include renderer ; … new Webpage().popup(…); …} ! … new Webpage().popup(…); …} ! revise Webpage{ } } revise Webpage{ revise Webpage{ void popup(HTML text){ } ! Border getBorder() { Border getBorder() { warning(“disabled”); } ! } } // return a decorated window border } ! // return a decorated window border } !

  10. Link ¡declarations ! + 10 ! l 3 : HTML viewer ! l 3 : HTML viewer ! methodshell viewer ; l 2 : webBrowser ! methodshell viewer ; include renderer; include renderer; methodshell browser ; class Viewer{ class Viewer{ void check(File f) { void check(File f) { include renderer; void check(File f) { … new Webpage().popup(…); …} ! … new Webpage().popup(…); …} ! revise Webpage{ } … new Webpage().popup(…); …} ! } revise Webpage{ revise Webpage{ void popup(HTML text){ } ! Border getBorder() { Border getBorder() { Border getBorder() { warning(“disabled”); } ! // return a decorated window border } ! } // return a decorated window border } ! } // return a decorated window border } ! Application ! method call ! methodshell application ; include browser; link viewer; include link main(){ new Viewer().check(…); context1 new Webpage().popup(); context2 n When the method in the linked methodshell is called, the current context switches to the context containing the called method.

  11. + An ¡Entire ¡Picture ! 11 ! void popup(HTML text){ void popup(HTML text){ // show a popup window } ! // show a popup window } ! renderer methodshell void popup(HTML text){ warning(“disabled”); } ! browser viewer viewer methodshell ! methodshell ! methodshell ! void check(File f) { void check(File f) { … … new Webpage().popup(…); new Webpage().popup(…); application …} ! …} ! methodshell ! include link main(){ new Webpage().popup(); context1 new Viewer.check(…); context2 }

  12. + Semantics ! 12 !

  13. + Method ¡Lookup ! 13 ! 5 ! renderer 1. Search the linked methodshell ! methodshell 2. Search the 1 ! 4 ! current context browser viewer methodshell ! methodshell ! 3. Search the global context ! 3 ! application method call ! methodshell ! 2 ! include application2 link methodshell ! context1 context2

  14. + A ¡Technique ¡for ¡Implementation ! 14 ! n To reduce runtime penalty n by transforming unique method names and method bodies to fit them at compile time method call ! application methodshell ! browser methodshell ! … revise Webpage{ main(){ void popup(HTML text){ … new Webpage().popup(…); … } } ! warning(“disabled”); } ! … Modified at compile time ! … main(){ void popup_browser(HTML text){ … new Webpage().popup_browser(…); warning(“disabled”); } ! … } …

  15. + Related ¡Work ! 15 ! n Context-oriented Programming[’08 Robert H, et al.] n Applied method declarations are changes by the current context n Classboxes[’05 Alexandre B, et al.] n Ruby’s refinements n controlling the scope of destructive class extensions. n NewSpeak[‘10 Bracha G, et al.] n All class names are virtual n Provide a mechanism corresponding to include declarations !

  16. + Conclusion ! 16 ! n Demand to modify the existing code n There are some mechanisms that make it easy to add and redefine methods n Proposal: Method Shells n a module system for switching applied definitions by context switches n Link and include declarations

  17. + Related ¡Work ! 17 ! n NewSpeak[‘10 Bracha G, et al.] n All class names are virtual n Provide a mechanism corresponding to include declarations n Method Shelter n Our previous study !

Recommend


More recommend