200 likes | 279 Views
Interfaces, Aspects, and Views. David Shepherd Dr. Lori Pollock University of Delaware. Example task. Given: Source code to JHotDraw, an open source drawing framework Context: Just coded CompositeFigure recently, but not updating correctly Task: Investigate and fix.
E N D
Interfaces, Aspects, and Views David Shepherd Dr. Lori Pollock University of Delaware
Example task . . . • Given: Source code to JHotDraw, an open source drawing framework • Context: Just coded CompositeFigure recently, but not updating correctly • Task: Investigate and fix
Observer Pattern in JHotDraw Observer (Display Area) must be notified when Subject (Rectangle) changes Display Area rectangle coordinates (1,5) rectangle coordinates (6,5) rectangle coordinates (6,5) Subject notify() Observer refresh screen
Coder Charlie - Step 1 • Looks in CompositeFigure • Suspects it is part of the Observer design pattern because implements FigureChangedListener
Coder Charlie - Step 2 • Follows type hierarchy to AbstractFigure • Because of knowledge of design pattern, suspects notify() (from Design Patterns) is there
Coder Charlie - Step 3 • Goes to AbstractFigure • Looks for notify() • Can you find it?
Coder Charlie - Step 3 cont'd • notify() = changed()
Coder Charlie - Step 4 • Goes back to CompositeFigure • Realizes should add call to changed() to figureChanged() • 1/2 of the job done right • needs to add willChange() too
Problem Cross-cutting concerns are often not implemented consistently • Code added throughout lifecycle • Different programmers • Forgetfulness • Unknown policy/convention • Even when explicit, as interface
Symptoms of Inconsistent Implementation • Decreased code quality • Decreased reliability • Decreased maintainability • (Possibly) missing functionality
Our Goal Improve implementation of cross-cutting concerns • Without increasing burden on programmer • Without large computational demands at user interaction time Introducing . . . Aspect Miner And Viewer (AMAV)
Technique - Aspect Miner...(AMAV) • Cluster related methods • Pluggable similarity metric • Simple Natural Language Processing (NLP) technique • Sub-string (method name) matching • Cluster related methods • Pluggable similarity metric • Simple Natural Language Processing (NLP) technique • Sub-string (method name) matching Class A Class B Class C Class D cacheMe persistB persistD willChange changed change cache persistC doCache getSize
Aspect MinerAnd Viewer (AMAV) • Show closely related methods in Virtual Source File (VSF) • Allows programmer to learn from other methods • Leads to consistency • Use tool for . . . • Initial coding, bug squashing • Refactoring opportunities VSF AMAV changed willChange doChange
Using AMAV During Implementation • New Coder: Plug-In-Hugger Paul • "I LUUUUUUV AMAV!" • Same task • Given: JHotDraw, an open source drawing framework • Context: Just coded CompositeFigure recently, but they are not updating correctly • Task: Investigate and fix AMAV Plug-in
Plug-In-Hugger Paul - Step 1 • Goes to CompositeFigure • Suspects composite is part of the Observer design pattern, because implements FigureChangedListener
Find figureChanged in ClusterViewer • Look at closely related methods • Follow their patterns • New implementation consistent Plug-In-Hugger Paul - Step 2a-c VSF
Task Results Why is Paul so happy? • He finished before poor Charlie • He had an easier time than Charlie • He won the company award for high quality code (he had a more consistent and correct implementation) • Best Parking Space
Charlie Examines Refactoring Opportunities • Browse through Cluster View... • Find (in top 15) VSF
Charlie Examines Refactoring Opportunities • Browse through Cluster View... • Find (in top 15) VSF
Conclusion • AMAV clusters related methods across classes • NLP-based similarity • Pluggable metric (possibly n dimensions) • AMAV integrates mining and viewing • AMAV helps with maintenance, implementation, evolution • Paul is home sleeping while Charlie is still at work, fixing his code • For details: www.cis.udel.edu/~shepherd/