Title: Formal Concept Analysis applied on Software Understanding
1Formal Concept Analysis applied on Software
Understanding
- Gabriela Arévalo
- Software Composition Group
- University of Berne (Switzerland)
- arevalo_at_iam.unibe.ch
- http//www.iam.unibe.ch/arevalo
2Roadmap
- Problems in Object Oriented Applications
- Concept Analysis
- CA on Classes X-Ray Views
- CA on Class Hierarchies Inheritance Patterns
- CA on Applications Software Patterns
- Lessons Learned and Conclusions
3Software Maintenance
- Maintenance of software systems 50 to 75 of
the total cost - Reading and Analysis of Software ½ time of
maintenance phase - Dependencies in the OO Applications
- Explicit inheritance, references to classes
- Implicit behavior reuse, collaborations among
classes - Understanding source code is a key activity
4Problems in Object Oriented Applications
- Class Hierarchies
- Behavior reuse between a class and its
superclasses and subclasses - Classes
- Definition and Use of state and behavior
- Application
- Structural and behavioral relationships between
classes
5Application of Concept Analysis
- Identifying groups of software artifacts with
similarities - Use of Concept Analysis
- Different Levels of Granularity of the system
- Approaches
- X-Ray Views Understanding the internals of a
class - Inheritance Patterns Analysing behavioral
dependencies in a class hierarchy - Software Patterns Detecting structural
relationships in an object oriented systems
6Concept Analysis Definitions
Top
- Specification of Elements and Properties
- Concept Maximal groups of elements based on
their common properties - Lattice partial order over the concepts
Bottom
7Why do we use Concept Analysis ?
- Simple Properties based on Elements
- Generation of concepts automatically
- Unanticipated combination of properties
- Order between the generated concepts
8ConAn Tool Architecture
X-Rays Views Software Patterns Inheritance
Patterns
Abstraction of the lattice
Identify groups
Concept Analysis
CA Pre-Filters
Keep one access to an attribute in a method
Element ltaddgt Property access firstIndex
CA Mapping
attribute
Class Ordered Collection
firstIndex
Code Representation
add
defines
Source Code
9X-Ray Views Concept Analysis on Classes
instance variables
Top
methods
Bottom
- Analysis of Accesses to State
- Elements (methods) Properties (accesses to
instances variables) - Analysis of Behavior
- Elements (methods) Properties (invocations to
other methods)
10X-Ray Views on Classes
- Collaborations Relationships of a set of methods
and a set of attributes
Class A
w
x
t
s
X-Ray View is a set of collaborations to show
patterns based on the state and behavior
z
y
m
n
a
b
d
c
11Class Understanding with X-Ray Views
- Mapping of each concept as a collaboration
- X-Ray View is a set of collaborations
- State Usage
- External / Internal Calls
- Behavioral Skeleton
- Validation 3 Classes in Smalltalk
- Ordered Collection 2 attributes and 56 methods
- UIBuilder 18 attributes and 122 methods
- Scanner 10 attributes and 24 methods
12Case Study Class CAContext
conceptsForElements conceptsForProperties
CAContext has 8 attributes and 63 methods
Behavior of Class
sigmaOf tauOf
setupWithContext
calculateLattice
createContext
deleteConcepts calculateConcepts
deleteLattice
addProperty
addElement
IR
concepts
lattice
lattice
lattice
lattice
properties
elements
conceptBuilt
latticeBuilt
conceptBuilt
conceptBuilt
conceptBuilt
conceptBuilt
latticeBuilt
conceptBuilt
conceptBuilt
latticeBuilt
latticeBuilt
State of Class
13Inheritance Patterns Example
- B define m2 and C defines m4 (abstract in A)
- B and C calls m3 defined in A via a super call
- B and C have a similar structure
14Inheritance Patterns Concept Analysis applied on
Hierarchies
A
Type of calls Definer Class
s1 ... m6 self s2
invocations
B
- Elements Invocations
- Properties type of calls and hierarchical
relationships with definer class
s2 ... s3 ... m5 super s1 m7 self
s3
15Pattern 1 Template methods and hook methods
ArithmeticValue squared self self -
- ltabstractgt ltabstractgt
- Abstract interface
- Concrete implementation in subclasses
- Framework add new concrete class, list of
methods to implement - Hot spots template methods and hook methods
Integer ltconcretegt - ltconcretegt
LargeInteger ltconcretegt - ltconcretegt
16Pattern 2 Self sends defined in ancestor
- Subclass interface
- Changes impact in all subclasses
- Refactoring identify common code in
sibling classes and define a new method in
superclass (ex compressed)
17Pattern 3 Local self send with super delegation
- Magnitude
- gt ltconcretegt
- ltconcretegt
- Delegation between methods
- Behavior defined in the superclass
- Change behavior in the superclasses
causes effects in subclasses
- SmallInteger
- gt super gt
- super
- digitLength self gt
- highBitAux self
18Software Patterns
Abstract X
P
Z
Y
Abstract A
T
C
B
Software Patterns Common structural aspects
between classes
D
19Software Patterns Concept Analysis on OO Apps
2
A
C
P
Tuples of classes
1
3
A B C P X Y Z all classes in a system
- Elements Tuples of classes gt Number of
classes order - Properties Set of indexes to show relationships
in the tuples. (i,j)relation and (i)feature
20Simplify Results with Filters
2
A
C
P
Tuples of classes
1
3
(1,2)Subclass (3,2)Subclass (2)Abstract (3,2)Acces
ses
21Simplify Results with Filters
- Merging Equivalent Patterns
S
(T,U,S) (1,3)Sub (2,1)Acc
D
3
(D,E,F) (2,1)Sub (3,2)Acc
1
E
F
T
U
2
1
3
2
Permutation of indexes ? 1 -gt2, 2-gt1,
3-gt2 ?((1,3)Sub (2,1)Acc)) ((2,1)Sub
(3,2)Acc)) gt (T,U,S) is transformed in (S,T,U)
22Found Software Patterns
Subclass Star
Attribute Star
Order 3
Order 4
Order 3
Order 4
Composite
Bridge
Order 3
Order 4
Order 3
Order 4
23Pattern Neighbourhood (1/2)
Almost Pattern
A
X
B
C
Y
Z
A
O3
B
C
A
B
C
Overloaded Pattern
24Pattern Neighbourhood (2/2)
Cover Pattern
A
D
O4
B
C
A
O3
B
C
O2
A
A
B
C
Sub Pattern
25Example CodeCrawler
- CodeCrawler has 81 classes and 1077 methods
- Statistics 6 patterns in order 2 and 24
patterns in order 3
26Lessons Learned
- Inference of implicit relationships
- Combination of simple properties (ex template
and hook methods) - Recognition of Patterns
- Classification of the results using abstractions
- Quality of Properties
- Iterative Process to identify meaningful
properties
27Conclusions (1/2)
- Use of Concept Analysis
- Promising Technique automatic generation of
groups - Properties must be simple
- Elements have few similarities
- Explosion in number of concepts
- Lattice is used partially
- Some concepts have no meaningful information
28Conclusions (2/2)
- Collaborations about different aspects of a
class/hierarchies/applications - Scalable approach small and large applications
- Complementary patterns in different granularity
levels - Interpretation is hard iterative application of
views and opportunistic code reading
29The End
x
w
t
s
z
y
n
m
a
c
b
d
Concept Analysis
w
x
t
s
z
y
m
n
a
b
d
c