UiPath Community: Communication Mining from Zero to Hero
A New Reusability Metric for Object-Oriented Software
1. A New Reusability Metric for
Object-Oriented Software
JUDITH BARNARD*
Department of Computing, The Open University, Milton Keynes, MK7 6AA, UK
Received August 1997
Angggha Satya Nugraha
Irene Ully Havsa
Indah Kuntum Khairina
* This paper was written whilst the author was a research associate on the MOODproject at the Department of Computer Science, University of
Warwick, Coventry, CV4 7AL, UK
2. Introduction
• The benefit of reuse:
- Reducing project cost
- Reducing project time
- Improving software quality
Make it more maintainable
3. Motivation
• How can the developer measure the reusability
of their software’s component?
• What guidelines can developers take to ensure
they are developing reusable software?
METRIC
4. Motivation
Why metric?
With a reusability metric, a component can be
given a value for reusability that will
determine if it reusable or not!
Then, what’s the factors that include in reusability
metric?
5. Discussion on Reusability
Class metrics
Attribute metrics
Reusability metric
Method metrics
Method input parameter
metrics
6. Class Metrics
Class Factors Quantifier
Coupling (Foreign classes) Coupling between object classes (CBO)
Number of methods Number of methods
Number of attributes Number of attributes
Meaningful name Rating 1-5 (1-low, 5-high)
Documentation Number of words in text existing ‘outside’ of the program
Lines of code Number of non-comment source code lines
Comment lines Number of comment lines per line of code
Depth of inheritance Depth of inheritance tree (DIT)
Number of children Number of children (NOC)
Cohesion Lack of cohesion in method (LCOM)
Class variables Number of class variables per line of code
Go to discussion
7. Attribute Metrics
Attribute factors Quantifier
Meaningful name Rating 1 to 5 (1-low, 5-high)
Complexity of data structure Number of sub-types
Go to discussion
8. Method Metrics
Method factors Quantifier
Meaningful name Rating 1 to 5 (1-low, 5-high)
Functions performed Number of functions performed
Lines of code Number of non-comment source code lines
Interface parameters Number of input parameters
Calls to foreign classes Number of calls to foreign classes per line of code
Calls to library classes Number of calls to library classes per line of code
Robustness Coverage of input parameters satisfied – expressed
as fraction between 0 and 1, 0-no coverage, 1-full
coverage
Complexity McCabe complexity measure
Instance variables Number of instance variables per line of code
Access Public, protected or private
Go to discussion
9. Method Input Parameter Metrics
Method input parameter factors Quantifier
Meaningful name Rating 1 to 5 (1-low, 5-high)
Parameter complexity Number of sub-types
10. Empirical Work
• This section contains the result of 2 experiments
that were carried out
• Steps:
1. Making highly reusable code and highly
unreusable code
2. Taking metrics from both types of code
3. Analyzing the results
4. Making some deduction
11. Experiment 1
Developer A
was asked to write the code in a very unreusable
manner and would be difficult to reuse elsewhere.
Developer B
was instructed to write the code in the most reusable
manner possible.
Compare both sets of classes (the
quantifiers, identified above, were applied to each
piece of code and their values compared).
17. Conclusion Experiment 1 (Class)
• Some interesting information arises from these
results. Both CBO and LCOM differ widely
between the reusable and unreusable code.
Reusable: low Reusable: 0
CBO LCOM
Unreusable: high Unreusable: high
• Other factors do not show any trend between
reusable and unreusable code
See the result
18. Conclusion Experiment 1 (Attribute
and Inp.param)
• Show general trend of needing to be simple.
See the result
See the result
19. Conclusion Experiment 1 (Method)
Reusable Code Unreusable Code
Perform only one function Perform not always one
Has no calls to foreign class Has calls to foreign class
• The remaining factors i.e lines of code, number of
input parameter do not provide any useful
information.
See the result
See the result
20. Conclusion Experiment 1
• Experiment 1 was a quick, easy experiment to
show where the general trends between reusable
and unreusable code lie, in terms of the factors
chosen.
• To confirm and enhance any theories that have
been arisen, further experiments must be carried
out.
21. Experiment 2
• This experiment involves the analysis of a wide
selection of reusable classes taken from well
used and accepted programming libraries.
• By taking a significant number of classes in this
study (30 classes in this case with over 200
methods), we will show any trends that can be
taken literally.
22. Experiment 2
• From any graphs below, we are looking for
factors that give a constant trend for all the
classes. Those that vary widely for all the
different classes we can assume to be unrelated
to reusability.
32. Result Experiment 2
• The graphs that show a constant trend for all the
classes are related to the following factors: CBO
for foreign classes (always zero), class
documentation, meaningful names (for
class, method, attribute and parameters), DIT
(low values – 0 or 1), the number of functions
within a method.
33. Result Experiment 2
• The graphs that do not show a constant trend for
all the classes are related to the following
factors: number of methods and attributes in a
class, number of lines of code and comment
lines, LCOM, number of input
parameters, method complexity and the number
of instance variables.
• The next section discusses these results and puts
forward a model and metric of reusability.
36. New Reusability Metric (Formula)
• The reusability metric, Reusability, for a class is
defined as:
>10: reusable
cm ca
Reusability R Rc m R c a m i a j
i 1 j 1
where
Rc MD c MN c CBO+DIT+1 <5 : unreusable
p
Rm i
MN m i
+MCi + Rp k
p NFi +NFCi
k 1
Rp k
MN p PCi k
1 or Rp k
5 if p 0
Ra f
MN a j
AC j 1
cm number of methods in class
ca number of attributes in class
p number of input parameter of method i
i, j , k variable integers
37. Reusability Metric in Ours
______________________________
Aplikasi Reusability Metric pada
Kode Sumber Tugas 1
39. CBO DIT
Coupling Between
Depth of Inheritance
Object
CLASS
MN MD
Meaningful
Meaningful Name
Description
40. Coupling between Object Classes
• Banyaknya kelas lain yang digunakan oleh suatu
Definisi kelas
• CBO semakin kecil semakin reusable
Hubungan
• Jumlah kelas lain yang terhubung dari kelas A oleh
Perhitungan hubungan asosiasi (non-inheritance)
Acceptable
•0–1
range
42. Coupling between Object Classes (3)
• CBO setiap kelas pada aplikasi Character Graphics:
Kelas CBO
Tool 1
DrawingPackage 3
Screen 0
ShapeList 1
CShape 1
CRect 1
CCircle 1
CTextBox 1
43. Depth of Inheritance Tree
• Jarak maksimum dari suatu simpul ke akar pada
Definisi inheritance tree
• DIT semakin kecil semakin reusable
Hubungan
• Jarak maksimum dari kelas A ke root pada
Perhitungan inheritance tree
Acceptable
•0–1
range
44. Depth of Inheritance Tree (2)
• DIT setiap kelas pada aplikasi Character Graphics:
Kelas DIT
Tool 0
DrawingPackage 0
Screen 0
ShapeList 0
CShape 0
CRect 1
CCircle 1
CTextBox 2
45. Meaningful Name
• Tingkat kejelasan kegunaan class dilihat dari
Definisi namanya
• MN semakin besar semakin reusable
Hubungan
• Tergantung asumsi & kebutuhan pihak
Perhitungan developer, juga bahasa yang digunakan
Acceptable
•4–5
range
46. Meaningful Name (2)
• Asumsi yang kami gunakan:
▫ Dalam Bahasa Inggris : +1
▫ Berupa kata benda : +1
▫ ‘Camel case’ : +1
▫ Menggambarkan kegunaan class : +2
47. Meaningful Name (3)
• Contoh MN untuk kelas DrawingPackage:
Penilaian :
• Dalam Bahasa Inggris : +1
• Berupa kata benda : +1
• ‘Camel case’ : +1
• Menggambarkan kegunaan kelas : +2
MN = 5
48. Meaningful Name (4)
• MN setiap kelas pada aplikasi Character Graphics:
Kelas MNc
Tool 5
DrawingPackage 5
Screen 5
ShapeList 5
CShape 5
CRect 4
CCircle 5
CTextBox 5
49. Meaningful Description
• Tingkat kejelasan kegunaan class dilihat dari
Definisi deskripsi/dokumentasinya.
• MD semakin besar semakin reusable
Hubungan
• Tergantung asumsi & kebutuhan pihak developer
Perhitungan
Acceptable
•4–5
range
50. Meaningful Description (2)
• Asumsi yang kami gunakan:
▫ Ada deskripsi kelas : +2
▫ Ada deskripsi atribut : +1
▫ Ada deskripsi method : +1
▫ Ada dokumentasi eksternal : +1
51. Meaningful Description (3)
• Contoh MD untuk kelas CTextBox:
Penilaian :
• Ada deskripsi kelas : +2
• Ada deskripsi atribut : +1
• Ada deskripsi method : +1
• Ada dokumentasi eksternal : 0
MD = 4
52. Meaningful Description (4)
• MD setiap kelas pada aplikasi Character Graphics:
Kelas MDc
Tool 0
DrawingPackage 3
Screen 0
ShapeList 1
CShape 0
CRect 3
CCircle 0
CTextBox 4
54. AC MN
Attribute Complexity Meaningful Name
ATTRIBUTE
55. Attribute Complexity
• Kompleksitas struktur data dari atribut
Definisi
• AC semakin kecil semakin reusable
Hubungan
• Jumlah sub-tipe dari atribut
Perhitungan
Acceptable
•0–1
range
56. Attribute Complexity (2)
• Contoh AC untuk atribut shapes pada kelas ShapeList:
Perhitungan:
Atribut shapes memiliki tipe Cshape,
CShape memiliki 3 subtipe, yaitu:
• CRect
• CCircle
• CTextBox
Sehingga untuk shapes, AC = 3
57. Attribute Complexity (3)
• Class Tool
Nama Atribut Tipe Atribut AC
drawingPackage DrawingPackage 0
• Class DrawingPackage
Nama Atribut Tipe Atribut AC
screen Screen 0
shapes ShapeList 0
currentBorder char 0
currentFill char 0
58. Attribute Complexity (4)
• Class Screen
Nama Atribut Tipe Atribut AC
screenRows int 0
screenColumns int 0
pixels char[][] 0
• Class ShapeList
Nama Atribut Tipe Atribut AC
maxObjects int 0
shapes Cshape[] 3
totalShapes int 0
59. Attribute Complexity (5)
• Class CShape
Nama Atribut Tipe Atribut AC
border char 0
fill char 0
selected boolean 0
screen Screen 0
• Class CCircle
Nama Atribut Tipe Atribut AC
centrex int 0
centrey int 0
radius int 0
60. Attribute Complexity (6)
• Class CRect
Nama Atribut Tipe Atribut AC
top int 0
left int 0
bottom int 0
right int 0
• Class CTextBox
Nama Atribut Tipe Atribut AC
fillText String 0
61. Meaningful Name
• Tingkat kejelasan kegunaan atribut dilihat dari
Definisi namanya
• MN semakin besar semakin reusable
Hubungan
• Tergantung asumsi & kebutuhan pihak developer,
Perhitungan juga bahasa yang digunakan
Acceptable
•4–5
range
62. Meaningful Name (2)
• Asumsi yang kami gunakan:
▫ Dalam Bahasa Inggris : +1
▫ ‘Mixed case’ : +1
▫ Menggambarkan kegunaan atribut: +3
63. Meaningful Name (3)
• Contoh MN untuk atribut drawingPackage pada kelas Tool:
Penilaian :
• Dalam Bahasa Inggris : +1
• ‘Mixed case’ : +1
• Menggambarkan kegunaan atribut: +3
MN = 5
64. Meaningful Name (4)
• Class Tool
Nama Atribut MNa
drawingPackage 5
• Class DrawingPackage
Nama Atribut MNa
screen 5
shapes 5
currentBorder 5
currentFill 5
65. Meaningful Name (5)
• Class Screen
Nama Atribut MNa
screenRows 5
screenColumns 5
pixels 5
• Class ShapeList
Nama Atribut MNa
maxObjects 5
shapes 5
totalShapes 5
66. Meaningful Name (6)
• Class CShape
Nama Atribut MNa
border 5
fill 5
selected 5
screen 5
• Class CCircle
Nama Atribut MNa
centrex 5
centrey 5
radius 5
67. Meaningful Name (7)
• Class CRect
Nama Atribut MNa
top 5
left 5
bottom 5
right 5
• Class CTextBox
Nama Atribut MNa
fillText 5
68. Perhitungan Ra
• Kelas Ra
Tool 5
DrawingPackage 5
Screen 5
ShapeList 3.75
CShape 5
CRect 5
CCircle 5
CTextBox 5
69. NF NFC
Number of Function Number of Calls to
Performed Foreign Classes
METHOD
MN MC
Meaningful Name Method Coverage
70. Number of Function Performed
• Jumlah fungsi yang dijalankan sebuah method
Definisi
• NF semakin kecil semakin reusable
Hubungan
• Jumlah tanda “ ; ” yang bukan pada variabel lokal
Perhitungan
Acceptable
•1
range
71. Number of Function Performed (2)
• Method RemoveShape pada Class ShapeList
NF = 2
72. Number of Function Performed (3)
• Class Tool • Class Screen
Nama Method NF Nama Method NF
main 2 DrawPixel 1
ErasePixel 1
• Class DrawingPackage EraseRegion 1
Nama Method NF EraseAll 1
Initial 2 Refresh 1
Interact 5
ApplyDragTool 2
RedrawAll 5
73. Number of Function Performed (4)
• Class ShapeList
Nama Method NF
AddShape 1
RemoveShape 2
FirstShapeContaining 1
Select 1
UnselectAll 1
RemoveSelected 2
SetBorderOfSelected 1
SetFillOfSelected 1
DrawAll 1
Reorder 1
74. Number of Function Performed (5)
• Class CShape
Nama Method NF
Draw 3
Drag 2
SetBorder 1
SetFill 1
Select 1
Unselect 1
Selected 1
Untuk Abstract method langsung di CRect dan CCircle
75. Number of Function Performed (6)
• Class CRect • Class CCircle
Nama Method NF Nama Method NF
Contains 1 Contains 1
Intersects 1 Intersects 1
DrawFill 1 DrawFill 1
DrawShape 1 DrawShape 1
DrawHandle 1 DrawHandle 1
OnResizeHandle 1 OnResizeHandle 1
Resize 2 Resize 1
Move 4 Move 2
76. Number of Function Performed (7)
• Class CTextBox
Nama Method NF
DrawFill 1
77. Number of Calls to Foreign Classes
• Jumlah pemanggilan method atau constructor dari
Definisi class lain
• NFC semakin kecil semakin reusable
Hubungan
• Jumlah distinct class yang method-nya digunakan
Perhitungan (tidak termasuk library)
Acceptable
•0–1
range
78. Number of Calls to Foreign Classes (2)
• Method Select pada Class ShapeList
NFC = 1
79. Number of Calls to Foreign Classes (3)
• Class Tool • Class Screen
Nama Method NFC Nama Method NF
main 1 DrawPixel 0
ErasePixel 0
• Class DrawingPackage EraseRegion 0
Nama Method NFC EraseAll 0
Initial 0 Refresh 0
Interact 1
ApplyDragTool 2
RedrawAll 1
80. Number of Calls to Foreign Classes (4)
• Class ShapeList
Nama Method NFC
AddShape 0
RemoveShape 0
FirstShapeContaining 1
Select 1
UnselectAll 1
RemoveSelected 1
SetBorderOfSelected 1
SetFillOfSelected 1
DrawAll 1
Reorder 1
81. Number of Calls to Foreign Classes (5)
• Class CShape
Nama Method NFC
Draw 0
Drag 0
SetBorder 0
SetFill 0
Select 0
Unselect 0
Selected 0
Untuk Abstract method langsung di CRect dan CCircle
82. Number of Calls to Foreign Classes (6)
• Class CRect • Class CCircle
Nama Method NFC Nama Method NFC
Contains 0 Contains 0
Intersects 0 Intersects 0
DrawFill 1 DrawFill 1
DrawShape 1 DrawShape 1
DrawHandle 1 DrawHandle 1
OnResizeHandle 0 OnResizeHandle 0
Resize 0 Resize 0
Move 0 Move 0
83. Number of Calls to Foreign Classes (7)
• Class CTextBox
Nama Method NFC
DrawFill 1
84. Method Coverage
• Tingkat cakupan validasi terhadap nilai – nilai yang
Definisi digunakan dalam method
• NFC semakin kecil semakin reusable
Hubungan
• Nilai awal = 1. Jika ada validitas yang tidak di-
Perhitungan handle, nilai berkurang x poin (misal 0.1)
Acceptable
•1
range
85. Method Coverage (2)
• Method Interact pada Class DrawingPackage
MC = 1 – 4*(0.1)
= 0.6
86. Method Coverage (3)
• Class Tool • Class Screen
Nama Method MC Nama Method MC
main 1 DrawPixel 1
ErasePixel 1
• Class DrawingPackage EraseRegion 1
Nama Method MC EraseAll 1
Initial 1 Refresh 1
Interact 0.6
ApplyDragTool 1
RedrawAll 1
87. Method Coverage (4)
• Class ShapeList
Nama Method MC
AddShape 1
RemoveShape 1
FirstShapeContaining 1
Select 1
UnselectAll 1
RemoveSelected 1
SetBorderOfSelected 1
SetFillOfSelected 1
DrawAll 1
Reorder 1
88. Method Coverage (5)
• Class CShape
Nama Method MC
Draw 1
Drag 1
SetBorder 1
SetFill 1
Select 1
Unselect 1
Selected 1
Untuk Abstract method langsung di CRect dan CCircle
89. Method Coverage (6)
• Class CRect • Class CCircle
Nama Method MC Nama Method MC
Contains 1 Contains 1
Intersects 1 Intersects 1
DrawFill 1 DrawFill 1
DrawShape 1 DrawShape 1
DrawHandle 1 DrawHandle 1
OnResizeHandle 1 OnResizeHandle 1
Resize 1 Resize 1
Move 1 Move 1
91. Meaningful Name
• Tingkat kejelasan kegunaan method dilihat dari
Definisi namanya
• MN semakin besar semakin reusable
Hubungan
• Tergantung asumsi & kebutuhan pihak
Perhitungan developer, juga bahasa yang digunakan
Acceptable
•4–5
range
92. Meaningful Name (2)
• Asumsi yang kami gunakan:
▫ Dalam Bahasa Inggris : +1
▫ Berupa kata kerja : +1
▫ ‘Mixed case’ : +1
▫ Menggambarkan kegunaan method : +2
93. Meaningful Name (3)
• Method FirstShapeContaining pada Class ShapeList
Penilaian :
• Dalam Bahasa Inggris : +1
• Berupa kata kerja : 0
• ‘Mixed case’ : 0
• Menggambarkan kegunaan method : +2
MN = 3
94. Meaningful Name (3)
• Class Tool • Class Screen
Nama Method MNm Nama Method MNm
main 5 DrawPixel 4
ErasePixel 4
• Class DrawingPackage EraseRegion 4
Nama Method MNm EraseAll 4
Initial 3 Refresh 4
Interact 4
ApplyDragTool 4
RedrawAll 4
95. Meaningful Name (4)
• Class ShapeList
Nama Method MNm
AddShape 4
RemoveShape 4
FirstShapeContaining 3
Select 4
UnselectAll 4
RemoveSelected 4
SetBorderOfSelected 4
SetFillOfSelected 4
DrawAll 4
Reorder 4
96. Meaningful Name (5)
• Class CShape
Nama Method MNm
Draw 4
Drag 4
SetBorder 4
SetFill 4
Select 4
Unselect 4
Selected 3
Untuk Abstract method langsung di CRect dan CCircle
97. Meaningful Name (6)
• Class CRect • Class CCircle
Nama Method MNm Nama Method MNm
Contains 4 Contains 4
Intersects 4 Intersects 4
DrawFill 4 DrawFill 4
DrawShape 4 DrawShape 4
DrawHandle 4 DrawHandle 4
OnResizeHandle 3 OnResizeHandle 3
Resize 4 Resize 4
Move 4 Move 4
99. MN PC
Parameter
Meaningful Name
Complexity
INPUT
PARAMETER
100. Meaningful Name
• Tingkat kejelasan kegunaan parameter dilihat dari
Definisi namanya
• MN semakin besar semakin reusable
Hubungan
• Tergantung asumsi & kebutuhan pihak developer,
Perhitungan juga bahasa yang digunakan
Acceptable
•4–5
range
101. Meaningful Name (2)
• Asumsi yang kami gunakan:
▫ Dalam Bahasa Inggris : +1
▫ ‘Mixed case’ : +1
▫ Menggambarkan kegunaan parameter : +3
102. Meaningful Name (3)
• Method Drag pada Class CShape
Penilaian :
1. startx
• Dalam Bahasa Inggris : +1
• ‘Mixed case’ : +1
• Menggambarkan kegunaan parameter: +3
• MN = 5
2. starty, endx, dan endy
• idem
103. Meaningful Name (4)
• Class Tool
Nama Method Parameter MNp
main argv 5
• Class DrawingPackage
Nama Method Parameter MNp
ApplyDragTool tool 5
startx 5
starty 5
endx 5
endy 5
104. Meaningful Name (5)
• Class Screen
Nama Method Parameter MNp
DrawPixel x 5
y 5
value 5
ErasePixel x 5
y 5
EraseRegion x1 5
y1 5
x2 5
y2 5
105. Meaningful Name (6)
• Class ShapeList
Nama Method Parameter MNp
AddShape shape 5
RemoveShape shape 5
FirstShapeContaining px 5
py 5
Select top 5
left 5
bottom 5
right 5
SetBorderOfSelected border 5
SetFillOfSelected fill 5
106. Meaningful Name (7)
• Class CShape
Nama Method Parameter MNp
Drag startx 5
starty 5
endx 5
endy 5
SetBorder border 5
SetFill fill 5
Untuk Abstract method langsung di CRect dan CCircle
107. Meaningful Name (8)
• Class CRect Nama Method Parameter MNp
Contains px 5
py 5
Intersects dtop 5
dleft 5
dbottom 5
dright 5
OnResizeHandle px 5
py 5
Resize dx 5
dy 5
Move dx 5
dy 5
108. Meaningful Name (8)
• Class CCircle Nama Method Parameter MNp
Contains px 5
py 5
Intersects dtop 5
dleft 5
dbottom 5
dright 5
OnResizeHandle px 5
py 5
Resize dx 5
dy 5
Move dx 5
dy 5
109. Parameter Complexity
• Kompleksitas struktur data dari parameter
Definisi
• PC semakin kecil semakin reusable
Hubungan
• Jumlah sub-tipe parameter
Perhitungan
Acceptable
•1
range
110. Parameter Complexity (2)
• Method AddShape ada ShapeList
Perhitungan:
Cshape memiliki 3 subtipe, yaitu:
• CRect
• CCircle
• CTextBox
Sehingga untuk shape, PC = 3
111. Parameter Complexity (4)
• Class Tool
Nama Method Nama Parameter Tipe Parameter PC
main argv String[] 0
• Class DrawingPackage
Nama Method Nama Parameter Tipe Parameter PC
ApplyDragTool tool char 0
startx int 0
starty int 0
endx int 0
endy int 0
112. Parameter Complexity (4)
• Class Screen
Nama Method Nama Parameter Tipe Parameter PC
DrawPixel x int 0
y int 0
value char 0
ErasePixel x int 0
y int 0
EraseRegion x1 int 0
y1 int 0
x2 int 0
y2 int 0
113. Parameter Complexity (5)
• Class ShapeList
Nama Method Nama Parameter Tipe Parameter PC
AddShape shape CShape 3
RemoveShape shape CShape 3
FirstShapeContaining px int 0
py int 0
Select top int 0
left int 0
bottom int 0
right int 0
SetBorderOfSelected border char 0
SetFillOfSelected fill char 0
114. Parameter Complexity (6)
• Class CShape
Nama Method Nama Parameter Tipe Parameter PC
Drag startx int 0
starty int 0
endx int 0
endy int 0
SetBorder border char 0
SetFill fill char 0
Untuk Abstract method langsung di CRect dan CCircle
115. Parameter Complexity (7)
• Class CRect Nama Method Nama Parameter Tipe Parameter PC
Contains px int 0
py int 0
Intersects dtop int 0
dleft int 0
dbottom int 0
dright int 0
OnResizeHandle px int 0
py int 0
Resize dx int 0
dy int 0
Move dx int 0
dy int 0
116. Parameter Complexity (9)
• Class CCircle Nama Method Nama Parameter Tipe Parameter PC
Contains px int 0
py int 0
Intersects dtop int 0
dleft int 0
dbottom int 0
dright int 0
OnResizeHandle px int 0
py int 0
Resize dx int 0
dy int 0
Move dx int 0
dy int 0