31
Mendel: A Model, Metrics, and Rules to Understand Class Hierarchies Simon Denier & Yann-Gaël Guéhéneuc Ptidej Team – Université de Montréal ICPC 2008 12/06/2008

ICPC08a.ppt

Embed Size (px)

Citation preview

Page 1: ICPC08a.ppt

Mendel:A Model, Metrics, and Rules

to Understand Class Hierarchies

Simon Denier & Yann-Gaël GuéhéneucPtidej Team – Université de Montréal

ICPC 2008 12/06/2008

Page 2: ICPC08a.ppt

22 / 28 / 28

Outline Motivation and Problem Mendel Model Interesting Classes Subclassing Behaviors Conclusion

Page 3: ICPC08a.ppt

33 / 28 / 28

Motivation Context: maintenance of program without documentation

Task: identify and understand the role of multiple classes

Problem 1: where to start? Find entry points (main(...)) Read large classes (by LOC or Number of Methods)

Problem 2: what about inheritance?

Page 4: ICPC08a.ppt

44 / 28 / 28

Problem: Class Hierarchies Classes defined incrementally by inheritance

Class “interesting” in its own hierarchy Class profiting from its hierarchy

Page 5: ICPC08a.ppt

55 / 28 / 28

Class Hierarchies

JHotDraw5.2

Page 6: ICPC08a.ppt

66 / 28 / 28

Class Hierarchies (2)

Azureus2.4.0.2

Page 7: ICPC08a.ppt

77 / 28 / 28

Outline Motivation and Problem Mendel Model Interesting Classes Subclassing Behaviors Conclusion

Page 8: ICPC08a.ppt

88 / 28 / 28

Mendel Approach Goal: insights on class hierarchies

Interesting classes in their own hierarchy Subclassing behaviors: extending (adding) vs overriding

Characteristics (requirements) of our approach Early stage in maintenance Intuitive Fast

Page 9: ICPC08a.ppt

99 / 28 / 28

Mendel: Generic Model

A

foo()bar()

B

bar()zorg()

Simple UML

bar()

foo()

zorg()New

Overridden

InheritedSuper

Local

Total

B

Mendel

Page 10: ICPC08a.ppt

1010 / 28 / 28

Mendel: Metrics and Rules Simple metrics:

Based on interfaces = sets of method signatures Computed on a single class or a hierarchy

Rules for: Selection (threshold) Classification Comprehension (rule of thumb)

Page 11: ICPC08a.ppt

1111 / 28 / 28

Outline Motivation and Problem Mendel Model Interesting Classes Subclassing Behaviors Conclusion

Page 12: ICPC08a.ppt

1212 / 28 / 28

Interesting Classes Classes defining a lot of new behaviors Large class: overall system

Budding class: with respect to its hierarchy

Blooming class: large and budding

Page 13: ICPC08a.ppt

1313 / 28 / 28

Large Class Class with a large interface Large Class: |Local| > threshold( |Local| )

JHotDraw1.StandardDrawingView (inherits from JPanel), 55 methods2.DrawApplication (inherits from JFrame), 53 methods3.AbstractFigure (inherits from Object), 34 methods

Page 14: ICPC08a.ppt

1414 / 28 / 28

Budding Class Class with a large interface with respect to its hierarchy Metrics:

Branch Mean Size – bms = |Total| / (DIT + 1) Novelty Index – nvi = |Local| / bms(superclass)

Budding class: nvi > threshold(nvi)

JHotDraw1.AbstractFigure, 3.092.TextFigure, 1.843.PolygonFigure, 1.59

Page 15: ICPC08a.ppt

1515 / 28 / 28

Blooming Class Synthesis: combining large and budding Novelty Score – nvs = |Local| × nvi Blooming Class: nvs > threshold(nvs)

JHotDraw1.AbstractFigure, 105.092.TextFigure, 55.13.LineConnection, 49.55

Page 16: ICPC08a.ppt

1616 / 28 / 28

JHotDraw Overview with Mendel JHotDraw 5.2: 148 classes

13 large (9%) 18 budding (12%) 11 blooming (7%)

Among 11 blooming classes 8 in AbstractFigure hierarchy + DrawApplication, StandardDrawingView, ConnectionTool

Page 17: ICPC08a.ppt

1717 / 28 / 28

JHotDraw Base Classes Given documentation: 6 base classes

Page 18: ICPC08a.ppt

1818 / 28 / 28

Comparison with Documentation 5 out of 6 in at least one set

AbstractFigure in all 3 sets

Budding

Large

Blooming

Page 19: ICPC08a.ppt

1919 / 28 / 28

What about StandardDrawing? Max rank: 16th by |Local| order Reason: overrider of CompositeFigure (4th blooming class) Conclusion: StandardDrawing to be understood in relation

with CompositeFigure

Page 20: ICPC08a.ppt

2020 / 28 / 28

Outline Motivation and Problem Mendel Model Interesting Classes Subclassing Behaviors Conclusion

Page 21: ICPC08a.ppt

2121 / 28 / 28

Subclassing Behaviors

INH INHINH INH

OVR OVROVR

NEW NEW NEW

Overrider Extender Pure ExtenderPure Overrider

|NEW|=0 |OVR|≥|NEW| |NEW|>|OVR| |OVR|=0

Page 22: ICPC08a.ppt

2222 / 28 / 28

Extender vs Overrider Rules of thumb Pure extender

Adding new methods: no access through superclass Used for itself Implementation inheritance

Pure overrider Overriding methods Used through substitution to superclass Interface inheritance

Page 23: ICPC08a.ppt

2323 / 28 / 28

JHotDraw in Verso

Page 24: ICPC08a.ppt

2424 / 28 / 28

Azureus in Verso

Page 25: ICPC08a.ppt

2525 / 28 / 28

Implementation in Java Tailored for Java

BCEL as class files parser

Performance for Azureus (1681 classes) Standard desktop machine (2Ghz processor, 1Go memory) 9 seconds

Page 26: ICPC08a.ppt

2626 / 28 / 28

Outline Motivation and Problem Mendel Model Interesting Classes Subclassing Behaviors Conclusion

Page 27: ICPC08a.ppt

2727 / 28 / 28

Conclusion Mendel

Generic model Simple metrics Rules

Results Quick insights on interesting classes and concerns

Large, budding, blooming: different views of interesting classes Concerns: keywords in classnames

Different usage of inheritance in programs Some leaned to extending (Log4J, Azureus) Others to overriding (JHotDraw, ArgoUML)

Page 28: ICPC08a.ppt

2828 / 28 / 28

Future Work Family analysis

Family = class + children Common behavior and interface

Visualisation Hierarchy representation Visual patterns

Page 29: ICPC08a.ppt

2929 / 28 / 28

ArgoUML in Verso

Page 30: ICPC08a.ppt

3030 / 28 / 28

Blooming Classes Selectivity Log4J: 2 of 206 (1%)

LogBrokerMonitor (104 methods), Category Budding set: Appender hierarchy

ArgoUML: 18 of 1431 (1%) 2 very big classes: NSUMLModelFacade, FacadeMDRImpl Design choice: Facade design pattern Keywords in class names: two products, normal and MDR

Azureus: 54 of 1681 (3%) Keywords in class names: three concerns, download, peer, DHT

Page 31: ICPC08a.ppt

3131 / 28 / 28

Behaviors Discrimination Two categories

JHotDraw and ArgoUML: overriding behaviors Large proportions of Pure Overriders

Azureus and Log4J: extending behaviors Azureus: 58% of classes are Pure Extenders