1 Interfaces, Aspects, and Views David Shepherd Dr. Lori Pollock University of Delaware.
-
Upload
britton-cain -
Category
Documents
-
view
213 -
download
0
Transcript of 1 Interfaces, Aspects, and Views David Shepherd Dr. Lori Pollock University of Delaware.
1
Interfaces, Aspects, and Views
David ShepherdDr. Lori Pollock
University of Delaware
2
• Given: Source code to JHotDraw, an open source drawing framework
• Context: Just coded CompositeFigure recently, but not updating correctly
• Task: Investigate and fix
Example task . . .
3
Observer Pattern in JHotDraw
Observer (Display Area) must be notified when Subject (Rectangle) changes
Display Area
rectanglecoordinates(1,5)
rectanglecoordinates
(6,5)
refresh screen
rectanglecoordinates
(6,5)Subject
Observer
notify()
4
Coder Charlie - Step 1
• Looks in CompositeFigure
• Suspects it is part of the Observer design pattern because implements FigureChangedListener
5
Coder Charlie - Step 2
• Follows type hierarchy to AbstractFigure −Because of knowledge of
design pattern, suspects notify() (from Design Patterns) is there
6
Coder Charlie - Step 3
• Goes to AbstractFigure
• Looks for notify()
• Can you find it?
7
Coder Charlie - Step 3 cont'd
• notify() = changed()
8
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
9
Problem
Cross-cutting concerns are often not implemented consistently
• Code added throughout lifecycle
• Different programmers
• Forgetfulness
• Unknown policy/convention
• Even when explicit, as interface
10
Symptoms of Inconsistent Implementation
• Decreased code quality
• Decreased reliability
• Decreased maintainability
• (Possibly) missing functionality
11
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)
12
Class DClass CClass B
Technique - Aspect Miner...(AMAV)
Class A
change
cacheMe persistD
doCache
persistB
changedwillChange
persistC
getSize
cache
•Cluster related methods•Pluggable similarity metric
•Simple Natural Language Processing (NLP) technique•Sub-string (method name) matching
13
Aspect Miner And 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
changed
doChangewillChange AMAV
14
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 AMAVPlug-in
15
• Goes to CompositeFigure
• Suspects composite is part of the Observer design pattern, because implements FigureChangedListener
Plug-In-Hugger Paul - Step 1
16
Plug-In-Hugger Paul - Step 2a-c
•Find figureChanged in ClusterViewer•Look at closely related methods•Follow their patterns•New implementation consistent
VSF
17
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
18
Charlie Examines Refactoring Opportunities•Browse through Cluster
View...
•Find (in top 15)VSF
19
Charlie Examines Refactoring Opportunities•Browse through Cluster
View...
•Find (in top 15)VSF
20
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/