language independent detection of object oriented design
play

Language-Independent Detection of Object-Oriented Design Patterns - PowerPoint PPT Presentation

Language-Independent Detection of Object-Oriented Design Patterns Johan Fabry Vrije Universiteit Brussel, Programming Technology Lab johan.fabry@vub.ac.be 25 Aug 2003 Lang-Indep Detection of OO DP 1 Overview Research Goal DMP and Soul


  1. Language-Independent Detection of Object-Oriented Design Patterns Johan Fabry Vrije Universiteit Brussel, Programming Technology Lab johan.fabry@vub.ac.be 25 Aug 2003 Lang-Indep Detection of OO DP 1

  2. Overview ß Research Goal ß DMP and Soul ß Soul to SoulJava ß Base-Level Reification ß Design Pattern Detection ß Conclusion & Future Work 25 Aug 2003 Lang-Indep Detection of OO DP 2

  3. Research Goal ß Language-agnostic reasoning about OO programs ß Validate research in different OO - languages ß Soul: Reasoning about Smalltalk (coding conventions, DP, bad smells, …) ß Clear separation language indep / dep ß Validation: ST + Java detect BPP, DP 25 Aug 2003 Lang-Indep Detection of OO DP 3

  4. DMP and Soul ß DMP: ß Declarative language at meta-level ß OO language at base level ß Meta-level programs reason about structure of base-level ß Soul: ß Meta-level prolog-like programming language ß Smalltalk code can be embedded in prolog code 25 Aug 2003 Lang-Indep Detection of OO DP 4

  5. Soul Layering ‘Uses’ Layering: Inference Code LiCoR MLI Engine Repository 25 Aug 2003 Lang-Indep Detection of OO DP 5

  6. Inference engine ß Logic query with a variable: If class(?x) Inference Code LiCoR MLI Engine Repository 25 Aug 2003 Lang-Indep Detection of OO DP 6

  7. LiCoR ß Appropriate rule is triggered: class(?c) if variable(?c), generate(?c,[ExplicitMLI current allClasses)]) Inference Code LiCoR MLI Engine Repository 25 Aug 2003 Lang-Indep Detection of OO DP 7

  8. Meta Level Interface ß Link to the base-level: allClasses ^Smalltalk allClasses Inference Code LiCoR MLI Engine Repository 25 Aug 2003 Lang-Indep Detection of OO DP 8

  9. Code Repository ß Investigate the code: allClasses … Inference Code LiCoR MLI Engine Repository 25 Aug 2003 Lang-Indep Detection of OO DP 9

  10. Soul to SoulJava We discuss changes in inverse order. Inference Code LicoR MLI Engine Repository 25 Aug 2003 Lang-Indep Detection of OO DP 10

  11. Java Code Repository ß Use Frost to parse Java Code ß Assume correct java code ! ß Java 1.0 (+epsilon) parser ß Java Code = parse trees ß .java ‘File in’ in File Browser ß Java Code Browser 25 Aug 2003 Lang-Indep Detection of OO DP 11

  12. Java Code Browser 25 Aug 2003 Lang-Indep Detection of OO DP 12

  13. MLI For Java ß Uses Java Code Repository ß Implements ß all methods of ST MLI ß methods for interface support 25 Aug 2003 Lang-Indep Detection of OO DP 13

  14. Base-Level Reification ß Namespace [name|super|sub|classes] ß ->Through MLI ß Class [name|super|sub|ns|methods|iv] ß ->Through MLI ß InstVar [name|inClass|type] ß ->Through MLI ß Method [name|arglist] ß ->Through MLI 25 Aug 2003 Lang-Indep Detection of OO DP 14

  15. Method Body Reification ß Method bodies = logic parse tree form ß Smalltalk: count set: 0 = send(variable([#count])),[#set:],<[0]>) ß Java: count.set(0) = send(variable([#count])),[#set],<[0]>) ß Allows for easy verification: isMessageSend(send(?receiver, ?message,?arguments)) 25 Aug 2003 Lang-Indep Detection of OO DP 15

  16. Method Body Reification ß But Java has more PT elements! ß if-then-else, while, for, … ß Introduce new logic functor for each ß Logic Java Parse trees have different form! ß No transformation to ‘ST-compatible’ form ß Logic PT as similar as possible to Java code ß Needed for later work: Java PT manipulations ß Users of parse tree must take this into account 25 Aug 2003 Lang-Indep Detection of OO DP 16

  17. Parse Tree Traversal Layer ß PTT: Specific layer in LiCoR ß Recursively traverses parse trees ß Called with: ß ?found predicate ß ?process predicate ß ?env for results ß Provide lang-spec implementation 25 Aug 2003 Lang-Indep Detection of OO DP 17

  18. Parse Tree Traversal Layer ß PTT: Specific layer in LiCoR ß Recursively traverses parse trees isMessageSend ß Called with: ß ?found predicate ß ?process predicate ß ?env for results ß Provide lang-spec implementation 25 Aug 2003 Lang-Indep Detection of OO DP 18

  19. Parse Tree Traversal Layer ß PTT: Specific layer in LiCoR messageSendMessage( ß Recursively traverses parse trees send(?rec,?msg,?args), ?args) ß Called with: ß ?found predicate ß ?process predicate ß ?env for results ß Provide lang-spec implementation 25 Aug 2003 Lang-Indep Detection of OO DP 19

  20. Parse Tree Traversal Layer ß PTT: Specific layer in LiCoR ß Recursively traverses parse trees ß Called with: ß ?found predicate ß ?process predicate ß ?env for results ß Provide lang-spec implementation 25 Aug 2003 Lang-Indep Detection of OO DP 20

  21. Idioms ß Lang specific naming and coding conventions ß Accessor method name: ß Smalltalk : var name ß Java: ‘get’ + capitalized var name 25 Aug 2003 Lang-Indep Detection of OO DP 21

  22. Pattern Detection ß 4 patterns in 4 apps Smalltalk Java HotDraw Drawlets RefactoringBrowser JRefactory 25 Aug 2003 Lang-Indep Detection of OO DP 22

  23. Best Practice Patterns Double Dispatch One language-independent rule ß Two idiom rules ß selfReference ß varName ß HotDraw: 0, Drawlets:3 ß RefactoringBrowser: 17, JRefactory 174 ß 25 Aug 2003 Lang-Indep Detection of OO DP 23

  24. Best Practice Patterns Getting Method One language-independent rule ß Two idiom rules ß methodSelector ß gettingMethodName ß HotDraw: 35/75, Drawlets:33/270 ß RBrowser: 125/531, JRefactory 134/721 ß 25 Aug 2003 Lang-Indep Detection of OO DP 24

  25. Design Patterns Template Method Three language-independent rules ß Three idiom rules ß abstractSelector, abstractMethod ß selfReference ß HotDraw Fig: 3, Drawlets Fig: 42 (19 I) ß RBrowser: 43, JRefactory: 50 ß 25 Aug 2003 Lang-Indep Detection of OO DP 25

  26. Design Patterns Template Method Three language-independent rules ß Three idiom rules ß abstractSelector, abstractMethod ß selfReference ß Takes care of interfaces in Java HotDraw Fig: 3, Drawlets Fig: 42 (19 I) ß RBrowser: 43, JRefactory: 50 ß 25 Aug 2003 Lang-Indep Detection of OO DP 26

  27. Design Patterns Template Method Three language-independent rules ß Three idiom rules ß abstractSelector, abstractMethod ß selfReference ß HotDraw Fig: 3, Drawlets Fig: 42 (19 I) ß RBrowser: 43, JRefactory: 50 ß 25 Aug 2003 Lang-Indep Detection of OO DP 27

  28. Design Patterns Visitor Two language-independent rules ß Use double-dispatch rule ß Zero idiom rules ß HotDraw: 0, Drawlets: 0 ß RBrowser: 14, JRefactory: 174 ß 25 Aug 2003 Lang-Indep Detection of OO DP 28

  29. Conclusion Feasible to reason about OO software in a ß language-independent way Soul to SoulJava ß Source Code Repository (Parser & Storage) ß Meta-level Interface (Implement API) ß Parse tree & traversal (Convertor & Logic Rules) ß Idiom layer (As Needed) ß Growth Idiom Layer < growth Detection ß layer 25 Aug 2003 Lang-Indep Detection of OO DP 29

  30. Future Work More pattern detection rules ß Easy / Tricky / Too language-specific ß New languages ß Small impact on current language-indep rules ß New language versions ß Reasoning about Java Bytecodes ß Type inferencing ß Language-Independent code generation ß From UML, pattern descriptions ß 25 Aug 2003 Lang-Indep Detection of OO DP 30

  31. FAQ Static Typing vs Dynamic Typing ß No Type Inferencing (Yet) ß Types in var declarations: 1 idiom rule ß Interfaces ß Not widely used in patterns: 1 idiom rule ß Accuracy of detection ß No false positives, no false negatives ß Similar limitations as other approaches ß 25 Aug 2003 Lang-Indep Detection of OO DP 31

  32. LiCoR Structure 25 Aug 2003 Lang-Indep Detection of OO DP 32

  33. public void getFoo(){ if (foo == null) foo = factory.boot(); return foo;} public void getFoo() { foo = factory.boot(foo == null); return foo;} 25 Aug 2003 Lang-Indep Detection of OO DP 33

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend