Class Diagram

Download Report

Transcript Class Diagram

Towards a Unified Framework for
Measuring the Properties of Class
Diagrams Augmented with OCL
By: Eng. Mohamed Awad Elshaarawy
Supervisors: Prof. Dr. Ismail Taha,
Dr. Haitham S.Hamza
Date: 8th Jul, 2013
• Introduction
• Related Work
• Motivation
• Thesis Contribution
• Proposed Model
• Controlled Experiments and
Results
• Conclusion & Future Work
2
Introduction
Class Diagram
In software engineering, a class diagram in the Unified Modeling Language (UML) is a type of static
structure diagram that describes the structure of a system by showing the system's classes, their
attributes, operations (or methods), and the relationships among the classes
3
Introduction
OCL Object Constraint Language
1.
1
In order to write clear, understandable and standardized constraints, OCL
have been developed
2.
OCL is a formal, modeling, typed and pure expression language used to
2
specify (invariants, pre-and post conditions on operations and methods and as
navigation language
3
3.
Formal language for the definition of constraints and queries on UML models
4.
Declarative to add precise semantics
4
context CustomerCard
invariant correctDates:
validFrom.isBefore(goodThru)
isBefore(Date):Boolean is a Date operation.
context CustomerCard
invariant: owner.age() >= 18
context CustomerCard
invariant printedName:
printedName =
owner.title.concat(‘ ‘).concat(owner.name)
context Membership
4
Related Work
Class Diagram Metrics Brief
1
Chidamber &
Kemerer
2
Li & Henry
3
Brito
4
Lorenz &
Kidd’s
5
Briand
6
Marchesi
Chidamber and Kemerer proposed six metrics for the
measurement of OO systems. Only three of the six CK metrics
are available for a UML class diagram
Li and Henry defined metrics that tend to measure different
internal attributes such as coupling, complexity and size
Brito proposed MOOD metrics to measure the use of OO
design mechanisms such as inheritance, information
hiding, and polymorphism
Lorenz and Kidd’s proposed Class size metrics, Class
inheritance metrics and Class’ internals metrics
Briand et al provided metrics which could distinguish the
relationship between classes’ different type of interactions, and the
locus of impact of the interaction
Marchesi Proposed three categories of metrics: those related to
single classes, those related to packages and those related to the
system as a whole
5
Related Work
Class Diagram Metrics Brief
7
Harrison
8
Bansiya &
Davis
9
Genero
10
Zhou
11
Reynosa,
Genero
&Piattini
12
Cabot &
Teniente
Harrison et al. defined metric to measure the inter-class
coupling
Bansiya and Davis defined metrics for assessing design properties
such as encapsulation, coupling, cohesion, composition and
inheritance
Genero defined metrics to measure class diagram complexity, due
to the use of different kinds of relationships, such as associations,
generalizations, aggregations and dependencies, in relation with
their impact on external quality attributes such as class diagram
maintainability
Zhou only used one indicator, namely entropy distance based
structure complexity metric, to evaluate the complexity of class
diagrams
Reynosa, Genero &Piattini defined a metric suite for
measuring structural properties of OCL expressions
Cabot and Teniente presented a new metric to measure the
complexity of OCL expressions
6
Related Work
OCL Metrics Brief
1
Reynosa,
Genero
&Piattini
2
Cabot &
Teniente
Reynosa, Genero &Piattini defined a metric suite for
measuring structural properties of OCL expressions
Cabot and Teniente presented a new metric to measure the
complexity of OCL expressions
7
Motivation & Objectives
Motivation
Lack of an integrated metrics
suites that consider class
diagrams with its OCL
expressions as a one chunk.
1
An integrated framework has been
presented to assess the structural
properties of the class diagram made
using the unified modeling language
(UML) with considering the added
complexity involved when a class
diagram is augmented with expressions
written in (OCL)
Answering the question of
whether using OCL is in the
benefit and not only the
efficiency of the work but also the
effectiveness‘ of it.
2
A controlled experiment’s results
analysis has been provided answering
this common question.
Objectives
propose a unified framework
contains a set of “Integrated”
metrics, a set of new class diagram
metrics, a set of new OCL metrics in
additions to the well-known class
diagram and OCL metrics that have
been selected for their extensively
use, relevant scope and validity
1
presents the results of a
controlled experiment that
investigates the impact of using OCL
on class diagram comprehension
and maintainability
2
3
provide the theoretical and
empirical validation for the proposed
metrics
8
Proposed Model Brief
•
•
The structural properties will be measured are: size, length and coupling. And, the
scopes of measures are: class diagram, OCL expressions and class diagram
augmented with OCL (integrated metrics)
So, the proposed metrics structured as follows: three metrics suites size
measurement metrics suite, length measurement metrics suite and coupling
measurement metrics suite). Each suite consists of class diagram scope, OCL
expressions scope and integrated class diagram _OCL metrics
9
Size Measurement Metric Suite
Size Measurement Metrics
Suite
CdNC, CdNA, CdNM, CdNR,
CdNAss, CdNAgg, CdNDep,
CdNGen, CDNGenH,
CdNAggH
OcNL, OcNC, OcNI, OcNO,
OcNCond, OcNV, OcNaA,
OcNaM, OcNaR, OcNaC,
OcWNM, OcWNN, OcNoBj
Classes’ Density, Attributes’
Density, Methods’ Density,
Relations’ Density
Class Diagram Size Scope Metrics
The selected well known (existing literature) metrics are : CdNC(Class diagram
number of classes), CdNM (Class diagram number of methods), CdNAss (Class
diagram number of association relationships) for uni directional and bi directional
association, CdNAgg ( Class diagram no. of aggregation relationships), CdNDep
(Class diagram number of dependency relationships), CdNGen (Class diagram number
of generalization relationships), CdNGenH (Class diagram number of generalization
hierarchies ), CdNAggH (Class diagram number of aggregation hierarchies)
The proposed metrics are: CdNA (Class diagram number of attributes), CdNR (Class
diagram no. of relations) it can be calculated by: CdNR =CdNAss+ CdNAgg+ CdNDep+
CdNGen+ CdNGenH+ CdNAggH
10
Size Measurement Metric Suite
OCL Expressions Size Scope Metrics
OcNoBj (the no. of objects in Bexp where Bexp is the bag of objects accessed during the
evaluation of an expression),
OcWNM (OCL expressions Weighted No. of Messages),
OcWNN (OCL expressions Weighted No. of Navigations)
OcNL (OCL expressionsNo. of Lines),OcNC (OCL expressions No. of constraints),OcNI
(OCL expressions No. of Invariants),OcNO (OCL expressions No. of Operations)
Including operations Boolean type, operations on integer and real types, operations on
string types, operations on collection types and query operation, OcNCond (OCL
expressions No. of pre and post Conditions), OcNV (OCL expressions No. of Variables
defined through <<Definition>> constraints included number of variables defined by Let
expressions in an expression),
OcNaA (OCL expressions No. of accessed class diagram attributes),OcNaM (OCL
expressions No. of accessed class diagram Methods), OcNaR (OCL expressions No. of
accessed class diagram Relations),
OcNaC (OCL expressions No. of accessed classes)
11
Size Measurement Metric Suite
Integrated Size Scope Metrics
Classes' Density: The ratio of (total no. of accessed classes in OCL expressions /total
no. of classes within class diagram= OcNaC/CdNC) this represents the extra complexity
added to CdNC due to using OCL
Attributes' Density: The ratio of (total no. of accessed attributes In OCL expressions
/total no. of attributes within class diagram= OcNaA/CdNA) this represents the extra
complexity added to CdNA due to using OCL
Methods’ Density: The ratio of (total no. of accessed method. In OCL expressions /total
no. of methods within class diagram= OcNaM/CdNM) this represent the extra complexity
added to CdNM (no. of methods) due to using OCL
Relations' Density: The ratio of (total no. of accessed relations In OCL expressions /total
no. of relations within class diagram=OcNaR/CdNR) this represents the extra complexity
added to CdNR due to using OCL
12
Size Measurement Metric Suite
Theoretical validation
Following the property based framework of Briand, it has been assured
that all of the size metrics suite fulfill all of the following axioms that
characterize size metrics:
PropertySize.1 (Non-negativity): This property is directly proven
because it is impossible to obtain a negative value for all of the size
metrics suites
PropertySize.2 (Null value): Any system from the above described
three systems have no elements will lead to its related metrics =0
PropertySize.3 (Module Additivity): This property is directly proven
because the size of a system is equal to the sum of the sizes of its
modules
13
Length Measurement Metric Suite
Length Measurement Metrics Suite
3.4.1
CdMaxDIT,CdMaxHAgg
3.4.2 OcDN
3.4.3 Extra length
Class Diagram & OCL Length Scope Metrics
These metrics were grouped into: class diagram length scope metrics, OCL expressions length scope
metrics and class diagram augmented with OCL length scope metrics.
Class Diagram Length Scope Metrics:
CdMaxDIT (The maximum between the Depth of Inheritance DIT values obtained for each class of the
class diagram, The DIT value for a class within a generalization hierarchy is the length of the longest
path from the class to the root of the hierarchy) ,CdMaxHAgg (The maximum between the Hierarchical
Aggregation (HAgg) values obtained for each class of the class diagram ,The HAgg value for a class
within an aggregation hierarchy is the length of the longest path from the class to the leaves)Units.
OCL Expressions Length Scope Metrics:
OcDN : Depth of Navigations (DN) is the maximum depth of the navigation tree
Max Depth: the added length to the longest path from the class to others related classes in the
class diagram due to navigation tree build after using OCL
14
Length Measurement Metric Suite
Theoretical Validation
Following the property based framework of Briand, it has been assured that all
of the length metrics suite fulfill all of the following axioms that characterize
length metrics:
• PropertyLength.1 (Nonnegativity) and Null Value are straightforwardly
satisfied, the depth of a tree can never be negative, and an expression
without navigation has an empty tree.
• PropertyLength.2 (Nonincreasing monotonocity) for connected
components: If we add relationships between elements of a tree (classes or
interfaces) the depth of the tree does not vary.
• PropertyLength.3 (Nondecreasing monotonocity) for non- connected
components: Adding a relationship to two unconnected components (two
trees) makes them connected, and its length is not less than the length of
the two unconnected components.
• PropertyLength.4 (Disjoint modules): The depth of a tree is given by the
component that has more levels from the root to the leaves.
15
Coupling Measurement Metric Suite
Class Diagram Coupling Scope Metrics
Coupling Measurement Metrics
Suite
CdNPCAIC, CdNOCAIC,
CdNDCAEC, CdNOCAEC,
CdNPCMIC, Cd NOCMIC,
CdNDCMEC , Cd NOCMEC
OcNPT, OcWNM, OcWNO
and OcNAN
Classes Fan-In , Methods
Fan-In, Messages Fan-In
,Classes Fan-Out ,Methods
FanOut,Messages Fan-Out
These metrics were grouped into: class diagram coupling scope metrics, OCL expressions coupling
scope metrics and class diagram augmented with OCL coupling scope metrics. (Integrated metrics)
Class Diagram Coupling Scope Metrics:
CdNPCAIC (Number of coupling relationship to Parent classes if there is a Class-attribute interaction
between classes of Import coupling type) , CdNOCAIC (Number of coupling relationship to other
classes if there is a Class-attribute interaction between classes of Import coupling type ), CdNDCAEC
(Number of coupling relationship to descendant classes if there is a Class-attribute interaction between
classes of Export coupling type), CdNOCAEC (Number of coupling relationship to other classes if there
is a Class-attribute interaction between classes of Export coupling type), CdNPCMIC (Number of
coupling relationship to parent classes if there is a Class-Method interaction between classes of Import
coupling type ),CdNOCMIC (Number of coupling relationship to other classes if there is a Class-Method
interaction between classes of Import coupling type )
CdNDCMEC (Number of coupling relationship to descendant classes if there is a Class-Method
interaction between classes of Export coupling type,CdNOCMEC (Number of coupling relationship to
other classes if there is a Class-Method interaction between classes of Export coupling type)
16
Coupling Measurement Metric Suite
OCL Expressions Coupling Scope Metrics
OcNPT (The OCL expressions Number of Parameters whose types are classes
defined in the class diagram),
OcNAN (The OCL expressions Number of attributes referred through
navigations in an expression,
OcWNM (OCL expressions Weighted No. of Messages),
OcWNO (The OCL expressions Weighted Number of referred Operations
through navigations)
17
Coupling Measurement Metric Suite
Integrated Coupling Scope Metrics
•
•
•
•
•
•
Classes Fan-In: The extra number of classes due to using OCL expressions that
use a specific class above the classes that originally use this specific class in the
class diagram
Methods Fan-In: The extra number of Methods due to using OCL expressions
that use a specific method in OCL operations above the methods that originally
use this specific method in the class diagram
Messages Fan-In: The extra number of messages due to using OCL
expressions that use a specific message above the messages that originally use
this specific message in the class diagram
Classes Fan-Out: The extra number of classes due to using OCL expressions
that a specific class calls above the number of classes that originally have been
called by this class in the class diagram
Methods Fan-Out: The extra number of methods due to using OCL expressions
that a specific method calls above the number of methods that originally have
been called by this method in the class diagram
Attributes Fan-Out: The extra number of Attributes due to using OCL
expressions (let and call expressions) that a specific method calls above the
number of attributes that originally have been called by this Method in the class
diagram
18
Coupling Measurement Metric Suite
Theoretical Validation
Following the property based framework of Briand, it has been assured that all
of the coupling metrics suite fulfill all of the following axioms that characterize
coupling metrics:
• PropertyCoupling.1 (Non-negativity): Is directly proven, and it is
impossible to obtain a negative value for all of stated metrics
• PropertyCoupling.2 (Monotonicity): Is directly verified, adding import
interactions - in this case, DU-interactions (interaction from Data declaration
to data Used in an OCL expression)
• PropertyCoupling.3 (Merging Modules): This property can be expressed
for our context in the following way: “the sum of the import coupling of two
modules is no less than the coupling of the module which is composed of the
data used of the two modules”. The value of metrics for an expression which
consists of the union of two original expressions, is equal to the metrics of
each expression merged when the sets of classes, methods, attributes and
messages referred to in each original expression are disjointed, otherwise is
less than metrics of each merged expression
19
Controlled Experiment
Experiments Planning
Definition
The purpose of this experiment is to analyze UML class diagrams with its OCL
expressions proposed framework metrics and to evaluate the metrics results
with the subjects’ ratings results indicating the impact of using OCL, combined
with UML class diagrams on the understandability and maintainability degree.
Context & Material Selection
The context of the experiment is a group related to the area of Software
Engineering in different seniority levels. They were grouped into 4 groups (8
subjects per group) and each subject worked individually on each of the two
systems, using class diagram+OCL in one case and only class diagram in the
other.
Two comparable, in terms of complexity and size, class diagrams with their
OCL expressions representing (Royal& Loyal system and Hotel management
system) are used.
20
Controlled Experiment
Hypothesis Formulation
•
•
•
The impact of using OCL will be assessed on two dependent variables:
Understandability (U) and Maintainability (M) were measured according to the
subjects’ ratings (of the experiment’s designed questionnaires) targets the system
logic(U), and the ability of subjects to correctly specify the affected system elements
due to changes in requirements(M). The other dependent variable is Maintenance
time which is comprises the time to comprehend the class diagram, analyze the
required changes and to implement them.
The null hypothesis (H0): There is no significant correlation between the framework
metrics and the above variables
The alternative hypothesis (Ha): There is a significant correlation between the
framework metrics and the above variables
21
Controlled Experiment
Instrumentation:
• Besides the class diagrams with its OCL expressions separate documents, other
forms were used like a survey questionnaire was distributed to obtain information
about the subjects’ background. After the completion of both Understandability and
Maintenance tasks, forms were distributed that contains specific questions about the
system. Maintenance questions address the Maintainability variable
• All of the questions were covered different parts of the system, feasible to answer but
not trivial and could be answered with or without OCL.
• In addition, another after-lab questionnaire was distributed with questions addresses
the selected variables.Those questions were answered on a Likert scale from 1
(Strongly agree) to 5 (Strongly disagree)
Execution and Data Validation:
• The operations were done successfully and all the data have been collected including
subjects’ answers obtained from the responses of the experiment and the metrics
value
22
Classes’ Density
Attributes’ Density
Methods’ Density
Relations’ Density
Extra length
Classes Fan-In
Methods Fan-In
Messages Fan-In
Classes Fan-Out
Methods Fan-Out
Messages Fan-Out
Controlled Experiment
Understability
0.892
0.859
0.789
0.912
0.589
0.677
0.718
0.857
0.683
0.881
0.789
Maintainability
0.896
0.909
0.812
0.926
0.588
0.759
0.673
0.891
0.693
0.848
0.788
Spearman's correlation between the metrics and Understandability and Maintainability
we can conclude that there is a significant correlation between the
proposed integrated class diagram & OCL structural complexity metrics
and subject’s rating
23
Controlled Experiment II
0.667
p=0.049
0.72
1
p=0.
272
0.719
p=0.029
0.840
p=0.005
Messages Fan-Out
0.759
p=0.01
8
Methods Fan-Out
0.728
p=0.04
Classes Fan-Out
Messages Fan-In
0.671
p=0.006
Methods Fan-In
0.795
p=0.01
Classes Fan-In
0.803
p=0.009
Extra length
Relations’ Density
0.94
1
p=0
Methods’ Density
maintenance
time
Attributes’ Density
Classes’ Density
Null hypothesis, H0: There is no significant correlation between structural
complexity metrics and maintenance time
Alternative hypothesis, H1 : There is a significant correlation between
structural complexity metrics and maintenance time
By calculating the mean of the maintenance time
0.669
p=0.04
|It’s concluded that there is a significant
correlation between all the metrics and the
maintenance time
24
Conclusion
 This thesis shows how we defined a metric suite for measuring the overall Structural
Properties of a class diagram augmented with OCL
 Also, it shows the best way from our point of view to measure the Structural
Properties of a class diagram and the OCL expressions individually
 We validated our framework theoretically by using the property-based framework of
Briand et al. and classified it to size, length and interaction-based metrics for coupling
 A controlled experiment was done to validate the proposed framework empirically and
shows that there are correlations between the metrics and their tested variables. And
also shows that OCL, as a constraint language complementary to UML class
diagrams, is useful in helping understand system models facilitate change and
understanding
 Obviously that the benefits of using OCL may only be observed if subjects have
sufficient training and/or obtained sufficient experience in UML class diagrams and
OCL
25
Future Work
The extension of the proposed work to cover other UML diagrams is
very important to make a unified framework for measuring the overall
structural properties of UML diagrams which augmented with OCL
26
Q&A