Tool Support for Design Pattern Recognition at Model Level

advertisement
22 July 2009
COMPSAC 2009
Tool Support for
Design Pattern Recognition
at Model Level
Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and
Richard Amphlett (1)
(1)
School of Technology, Oxford Brookes University,
Oxford OX33 1HX, UK
(2) Dept. of Computer Science, National University of
Defense Technology, Changsha, China
1
Outline

Motivation and Related works

22 July 2009


Tool support to the application of DPs
Formalisation of DPs
Our Previous work

Specification of DPs
 Semantics of UML models

The proposed approach

Bridge the gaps
 The tool LAMBDES-DP
 Experiments

Conclusion and future work
COMPSAC 2009
2
Motivation
 Design
Patterns (DPs)
22 July 2009
 Reusable
Explained in
informal English
solutions to commonly occurring design
problems
 Represented in Alexandrian form
Clarified with
illustrative diagrams
 Synopsis, Context, Forces, Solution, Consequences,
Implementation, Examples, Related patterns
 Proper
use can improve software quality and
development productivity
Specific code examples
 Reduce ambiguity
 Automated tool support
COMPSAC 2009
3
Existing works 1: Tool support


Instantiation of patterns widely available in modelling tools
Pattern recognition tools
Low level of abstraction

Code level:
Late in development process
22 July 2009
 More than a dozen reported in the literature (Dong, Zhao and Peng, SERP
2007)
Hard to improve precision
and recall rate
 Well-known examples:
• HEDGEHOG (Blewitt, Bundy and Stark, ASE 2005)
• FUJABA (Niere, et al. ICSE 2002)
• PINOT (Shi and Olsson, ASE 2006)

Design/Model level
 (Kim and Lu, ICECCS’06): Translate RBML and UML into Prolog
 (Kim and Shen, SAC’07, SQJ 2008): RBMLCC
• Plug-in to IBM Rational Rose
• Pattern specified by metamodel in RBML
• Apply it to 7 of the 23 GoF patterns
• Class diagram only
COMPSAC 2009
4
Existing works 2: Formalisation of DPs
22 July 2009

Le Guennec et al. (UML 2000): the extension of the UML metamodel and OCL
 Eden (2001): the graphical language LePUS
 Mapelsden et al. (CRPIT ’02): Design Pattern Modeling
Language
 Taibi (2003, 2006) and Mikkonen (ICSE’98): the use of
predicate logic and temporal logic
 Kim, France, Ghosh, and Song (COMPSAC 2003): Role-based
metamodelling language RBML
 Bayley and Zhu (SEFM’07, COMPSAC’08, QSIC’08): first
order logic
 And many other works, e.g. Lano et al. (1996), Lauder and Kent
(1998), Mak, et al. (ICSE’04), Zdun and Avgeriou
(OOPLSA’05), etc.
COMPSAC 2009
5
Previous work 1: Specification of DPs

Formal meta-modelling in first order logic (Bayley and Zhu
2007, 2008)

22 July 2009



The abstract syntax of UML diagrams specified in GEBNF (Graphically
Extended BNF).
A first-order predicate logic (FOL) language systematically derived from
the abstract syntax definition
Specifying design patterns in the FOL as predicate on UML diagrams and
pattern instantiation is predicate satisfaction.
Advantages:
 Expressiveness:
• Both structural feature and behavioural features in the same FOL
• Variants of patterns can be specified
• All 23 GoF patterns are specified
 Readability:
• More readable than its rivals
 Facilitate reasoning, operations and transformations of DPs
• to formally prove their properties and relationships
• to compose patterns
COMPSAC 2009
6
Example: Template Method pattern
22 July 2009
=
COMPSAC 2009
7
Previous work 2: Semantics of UML models
Descriptive semantics of modelling language
(Shan and Zhu, 2008)
22 July 2009
 The
formal semantics of UML is resolved into two
aspects:
It describes the system without referring
to what is meant by class and subclass.
 descriptive semantics:
• defines which systems are instances of a model.
• e.g. the system consists of two classes A and B, and A
is a subclass of B.
Perhaps uses axioms on the
dynamic behaviour of systems.
 functional semantics:
• defines the basic modeling concepts,
• e.g. If class X is a subclass of Y, then all instances of X
are also instances of Y.
It defines the notion of class and subclass.
COMPSAC 2009
8
Translation of models into First Order Logic


22 July 2009


Signature mapping: rules to derive symbols of FOL from the metamodel
Axiom mapping: rules to derive statements in the FOL from the
metamodel that must be true for all valid models
Translation mapping: rules to translate a graphical model into predicates
in FOL that it is true if and only if a system is an instance of the model
Hypothesis mapping: rules that selected by the user to be applied in order
to characterise the context in which the model is used
COMPSAC 2009
9
Example:
The following is a subset of the
predicates generated from the diagram
22 July 2009

COMPSAC 2009
10
Bridging the Gap

Differences between the FOL for DP spec and the FOL
for UML semantics
22 July 2009


Syntactic difference
Semantic difference
 Predicates in a DP specification are evaluated on UML models
 Predicates in the descriptive semantics of UML models are evaluated
on software systems

DP specification is translated into the syntax of FOL for
descriptive semantics
COMPSAC 2009
11
Example:
The specification of Template Method can be translated
into:
22 July 2009

COMPSAC 2009
12
P is a pattern.
Spec(P) is the formal
specification of P.
22 July 2009
The descriptive
semantics of
model m.
System s satisfies
the specification.
System s is an
instance of model
m.
Recognition of a pattern at design level becomes a logic
inference problem.
COMPSAC 2009
13
22 July 2009
The Tool LAMBDES-DP
COMPSAC 2009
14
22 July 2009
Experiments:
1. Use StarUML to produce design instances as UML diagrams and
export them as XMI representations.
2. Use LAMBDES to convert these XMI representations to FOL;
3. Use LAMBDES to check these FOL representations for
consistency errors, revising them until there are no more errors;
4. For each pattern, use LAMBDES-DP to determine if the model
conforms to (i.e. implies the specification of) the pattern.
 Three possible outcomes:
 Proof Found, meaning definitely yes,
 Completion Found, meaning definitely no, and
 Time Out, meaning that no proof was found in the
maximum time limit that SPASS allows, which is 990
seconds.
COMPSAC 2009
15
Subjects of the experiments
 Patterns:
22 July 2009

23 Patterns in GoF book
 Design
Instances:
Two sets of design instances were produced manually
from the diagrams in the GoF book.
 Set 1 (Class Only): contains a class diagram for each
of the 23 patterns in the book.
 Set 2 (Class + Seq): contains class and sequence
diagrams for the only 6 patterns in the book that
contain both.
COMPSAC 2009
16
22 July 2009
Overview of the Design Instances: ClassOnly Set
COMPSAC 2009
17
22 July 2009
Overview of the Design Instances: Class+Seq Set
COMPSAC 2009
18
22 July 2009
Experiment Results
ClassOnly
Class+Seq
Recall
(False negative error rate)
0%
0%
Precision
(False positive error rate)
< 22%
0%
Conclusion:


Recognition of patterns at design level can be accurate with
good precision and recall rate;
Behavioural feature is crucial for accurate specification and
hence the recognition of patterns, as we have argued in
(Bayley and Zhu, COMPSAC 2008);
COMPSAC 2009
19
Future work

Improvement of the efficiency of LAMBDES-DP
22 July 2009


Enhance LAMBDES-DP functionality





SPASS cannot handle the inference of large logic systems
(when it has more than 1000 formulas, which is equivalent to
models that have more than 10 elements.)
Pattern composition
Pattern directed refactoring at design level
Reasoning about patterns
Experiment with industrial real systems
Integration with code level tools

Some tools extract information from code and represent the
extracted information in the form of first order logic
predicates
COMPSAC 2009
20
References

22 July 2009




I. Bayley and H. Zhu. Formalising design patterns in
predicate logic. In Proc. of SEFM’07, pp 25–36.
I. Bayley and H. Zhu. On the composition of design
patterns. Proc. of QSIC’08, pp27–36.
I. Bayley and H. Zhu. Specifying behavioural features
of design patterns in first order logic. Proc. of
COMPSAC’08, pp203–210.
L. Shan and H. Zhu. A formal descriptive semantics of
UML. Proc. of ICFEM’09, pp375–396.
L. Shan and H. Zhu, Semantics of Metamodels in
UML, Proc. of TASE’09. (In press)
COMPSAC 2009
21
Download