21
22 July 2009 COMPSAC 2009 1 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

22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

Embed Size (px)

Citation preview

Page 1: 22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

22 J

uly

2009

COMPSAC 2009

1

Tool Support for Design Pattern Recognition

at Model LevelHong 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

Page 2: 22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

22 J

uly

2009

2COMPSAC 2009

Outline

Motivation and Related works 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

Page 3: 22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

22 J

uly

2009

3COMPSAC 2009

Motivation

Design Patterns (DPs) Reusable solutions to commonly occurring design pr

oblems Represented in Alexandrian form

Synopsis, Context, Forces, Solution, Consequences, Implementation, Examples, Related patterns

Proper use can improve software quality and development productivity Reduce ambiguity Automated tool support

Explained in informal English

Clarified with illustrative diagrams

Specific code examples

Page 4: 22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

22 J

uly

2009

4COMPSAC 2009

Existing works 1: Tool support Instantiation of patterns widely available in modelling tools Pattern recognition tools

Code level: More than a dozen reported in the literature (Dong, Zhao and Peng, SERP 20

07) 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

Low level of abstractionLate in development process

Hard to improve precision and recall rate

Page 5: 22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

22 J

uly

2009

5COMPSAC 2009

Existing works 2: Formalisation of DPs Le Guennec et al. (UML 2000): the extension of the UML meta-

model and OCL Eden (2001): the graphical language LePUS Mapelsden et al. (CRPIT ’02): Design Pattern Modeling Langua

ge Taibi (2003, 2006) and Mikkonen (ICSE’98): the use of predicat

e 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.

Page 6: 22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

22 J

uly

2009

6COMPSAC 2009

Previous work 1: Specification of DPs Formal meta-modelling in first order logic (Bayley and Zhu

2007, 2008) 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

Page 7: 22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

22 J

uly

2009

7COMPSAC 2009

Example: Template Method pattern

=

Page 8: 22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

22 J

uly

2009

8COMPSAC 2009

Previous work 2: Semantics of UML models

Descriptive semantics of modelling language (Shan and Zhu, 2008) The formal semantics of UML is resolved into two a

spects: 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. 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 describes the system without referring to what is meant by class and subclass.

It defines the notion of class and subclass.

Perhaps uses axioms on the dynamic behaviour of systems.

Page 9: 22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

22 J

uly

2009

9COMPSAC 2009

Translation of models into First Order Logic 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

Page 10: 22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

22 J

uly

2009

10COMPSAC 2009

Example: The following is a subset of the

predicates generated from the diagram

Page 11: 22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

22 J

uly

2009

11COMPSAC 2009

Bridging the Gap Differences between the FOL for DP spec and the FOL

for UML semantics 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

Page 12: 22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

22 J

uly

2009

12COMPSAC 2009

Example: The specification of Template Method can be translated

into:

Page 13: 22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

22 J

uly

2009

13COMPSAC 2009

P is a pattern.Spec(P) is the formal specification of P.

The descriptive semantics of model m.

System s is an instance of model m.

System s satisfies the specification.

Recognition of a pattern at design level becomes a logic inference problem.

Page 14: 22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

22 J

uly

2009

14COMPSAC 2009

The Tool LAMBDES-DP

Page 15: 22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

22 J

uly

2009

15COMPSAC 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 consiste

ncy errors, revising them until there are no more errors;4. For each pattern, use LAMBDES-DP to determine if the model c

onforms 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 maxim

um time limit that SPASS allows, which is 990 seconds.

Page 16: 22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

22 J

uly

2009

16COMPSAC 2009

Subjects of the experiments

Patterns: 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 dia

grams for the only 6 patterns in the book that contain both.

Page 17: 22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

22 J

uly

2009

17COMPSAC 2009

Overview of the Design Instances: ClassOnly Set

Page 18: 22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

22 J

uly

2009

18COMPSAC 2009

Overview of the Design Instances: Class+Seq Set

Page 19: 22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

22 J

uly

2009

19COMPSAC 2009

Experiment ResultsClassOnly 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);

Page 20: 22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

22 J

uly

2009

20COMPSAC 2009

Future work Improvement of the efficiency of LAMBDES-DP

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.)

Enhance LAMBDES-DP functionality 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

Page 21: 22 July 2009 COMPSAC 2009 1 Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett

22 J

uly

2009

21COMPSAC 2009

References

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)