A Calculus of Design Patterns Hong Zhu Dept. of Computing and Electronics Oxford Brookes University Oxford OX33 1HX, Uk

Slides:



Advertisements
Similar presentations
SCL: A Logic Standard for Semantic Integration Christopher Menzel Philosophy Department Texas A&M University
Advertisements

A Formal Descriptive Semantics of UML Lijun Shan Dept of Computer Science National University of Defense Technology, Changsha, China Hong Zhu Department.
Recognition of Patterns in Software Designs Models via Logic Inferences Hong Zhu Department of Computing and Electronics Oxford Brookes University Oxford.
22 July 2009 COMPSAC Tool Support for Design Pattern Recognition at Model Level Hong Zhu (1), Ian Bayley (1), Lijun Shan (2) and Richard Amphlett.
Laws of Pattern Composition Hong Zhu and Ian Bayley Department of Computing and Electronics Oxford Brookes University Oxford OX33 1HX, Uk
Brief Introduction to Logic. Outline Historical View Propositional Logic : Syntax Propositional Logic : Semantics Satisfiability Natural Deduction : Proofs.
Cs7120 (Prasad)L22-MetaPgm1 Meta-Programming
10 October 2006 Foundations of Logic and Constraint Programming 1 Unification ­An overview Need for Unification Ranked alfabeths and terms. Substitutions.
1 CIS224 Software Projects: Software Engineering and Research Methods Lecture 11 Brief introduction to the UML Specification (Based on UML Superstructure.
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Primitive Recursive Functions (Chapter 3)
Copyright © Cengage Learning. All rights reserved.
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
Instructor: Hayk Melikya
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
1 Relational Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
1 Conditional XPath, the first order complete XPath dialect Maarten Marx Presented by: Einav Bar-Ner.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
1 Predicates and quantifiers Chapter 8 Formal Specification using Z.
Lesson 6. Refinement of the Operator Model This page describes formally how we refine Figure 2.5 into a more detailed model so that we can connect it.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
10 May 2009Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Formal.
Business Domain Modelling Principles Theory and Practice HYPERCUBE Ltd 7 CURTAIN RD, LONDON EC2A 3LT Mike Bennett, Hypercube Ltd.
Set Notation.
An Information Theory based Modeling of DSMLs Zekai Demirezen 1, Barrett Bryant 1, Murat M. Tanik 2 1 Department of Computer and Information Sciences,
Math 3121 Abstract Algebra I Lecture 3 Sections 2-4: Binary Operations, Definition of Group.
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
A Brief Summary for Exam 1 Subject Topics Propositional Logic (sections 1.1, 1.2) –Propositions Statement, Truth value, Proposition, Propositional symbol,
Math 3121 Abstract Algebra I Section 0: Sets. The axiomatic approach to Mathematics The notion of definition - from the text: "It is impossible to define.
A Z Approach in Validating ORA-SS Data Models Scott Uk-Jin Lee Jing Sun Gillian Dobbie Yuan Fang Li.
MATH 224 – Discrete Mathematics
Copyright 2002 Prentice-Hall, Inc. Modern Systems Analysis and Design Third Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich Chapter 20 Object-Oriented.
An Algebra for Composing Access Control Policies (2002) Author: PIERO BONATTI, SABRINA DE CAPITANI DI, PIERANGELA SAMARATI Presenter: Siqing Du Date:
Sequences and Summations
Chapter 7 Logic, Sets, and Counting Section 2 Sets.
1 Relational Algebra and Calculas Chapter 4, Part A.
Hong Zhu Dept of Computing and Communication Technologies Oxford Brookes University Oxford, OX33 1HX, UK TOWARDS.
Section 2.7 Solving Inequalities. Objectives Determine whether a number is a solution of an inequality Graph solution sets and use interval notation Solve.
Hong Zhu Department of Computing and Communication Technologies Oxford Brookes University, Oxford OX33 1HX, UK COMPSAC 2012 PANEL.
Propositional Calculus CS 270: Mathematical Foundations of Computer Science Jeremy Johnson.
CompSci 102 Discrete Math for Computer Science
1 Introduction to Abstract Mathematics Sets Section 2.1 Basic Notions of Sets Section 2.2 Operations with sets Section 2.3 Indexed Sets Instructor: Hayk.
Boolean Algebra and Computer Logic Mathematical Structures for Computer Science Chapter 7.1 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesBoolean Algebra.
Mathematical Preliminaries
2.1 Sets 2.2 Set Operations –Set Operations –Venn Diagrams –Set Identities –Union and Intersection of Indexed Collections 2.3 Functions 2.4 Sequences and.
Chapter 2 Logic 2.1 Statements 2.2 The Negation of a Statement 2.3 The Disjunction and Conjunction of Statements 2.4 The Implication 2.5 More on Implications.
Lecture 5 1 CSP tools for verification of Sec Prot Overview of the lecture The Casper interface Refinement checking and FDR Model checking Theorem proving.
Predicates and Quantifiers Dr. Yasir Ali. 1.Predicates 2.Quantifiers a.Universal Quantifiers b.Existential Quantifiers 3.Negation of Quantifiers 4.Universal.
Chapter 16: UML Class Diagrams
Duminda WijesekeraSWSE 623: Introduction1 Introduction to Formal and Semi- formal Methods Based on A Specifier's Introduction to Formal Methods (J. Wing)
Copyright © Cengage Learning. All rights reserved. CHAPTER 8 RELATIONS.
RelationsCSCE 235, Spring Introduction A relation between elements of two sets is a subset of their Cartesian products (set of all ordered pairs.
Relations and Functions ORDERED PAIRS AND CARTESIAN PRODUCT An ordered pair consists of two elements, say a and b, in which one of them, say a is designated.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
Interpreting the Object Constraint Presented by: Ed Kausmeyer.
A UML-Based Pattern Specification Technique Presented by Chin-Yi Tsai IEEE TRANSACTION ON SOFTWARE ENGINEERING, VOL. 30, NO. 3, MARCH 2004 Robert B. France,
Propositional Logic. Assignment Write any five rules each from two games which you like by using propositional logic notations.
Chapter 2 1. Chapter Summary Sets (This Slide) The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
The Relation Induced by a Partition
Dr. Ameria Eldosoky Discrete mathematics
Logic.
Relations and Functions
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 2 Sets Slides are adopted from “Discrete.
Chapter 20 Object-Oriented Analysis and Design
A Brief Summary for Exam 1
MA/CSSE 474 More Math Review Theory of Computation
Chapter 7 Logic, Sets, and Counting
SECTION 4: OO METHODOLOGIES
Presentation transcript:

A Calculus of Design Patterns Hong Zhu Dept. of Computing and Electronics Oxford Brookes University Oxford OX33 1HX, Uk

Seminar: A Calculus of Design Patterns2 Aug Acknowledgement Ian Bayley and Hong Zhu, A formal Language of Pattern Composition, Proc. of PATTERNS 2010, Nov (in press) Hong Zhu and Ian Bayley, Laws of Pattern Composition, Proc. of ICFEM 2010, Nov (in press) Ian Bayley and Hong Zhu, Formal specification of the variants and behavioural features of design patterns, Journal of Systems and Software Vol.83, No.2, pp209–221 (Feb 2010)

Seminar: A Calculus of Design Patterns3 Aug Overview Introduction Operators on patterns Case study 1: The expressiveness GoF suggested compositions Laws of pattern composition Case study 2: the proof of equivalence Representation of composition with overlaps Soundness of the operators Future work

Seminar: A Calculus of Design Patterns4 Aug Introduction Software Design Patterns (DP) codified reusable solutions to recurring design problems, increasingly important role in the development of software systems Research on DP identified and catalogued (e.g. Gang of Four book) formally specified (Mik 1998, Taibi 2003, Gasparis et al. 2008, Bayley&Zhu 2009) included in software tools (e.g. PINOT, Mapelsden et al. 2002)

Seminar: A Calculus of Design Patterns5 Aug Formal Specification of DPs Formal approaches Eden's approach Formal logic predicates on the structural features of the source code of object-oriented programs (Gasparis et al. 2008) Taibi's approach Formal logic predicates on the structural features of the source code Temporal logic statements for behavioural features Our predicates (Bayley & Zhu, 2007, 2008, 2009) Formal logic predicates for both structural and behavioural features of designs in UML class and sequence diagrams The primitive predicates are induced from GEBNF definition of UML Semi-formal approaches Uses of graphic meta-modelling languages For example: RBML, DPML, PDL, etc. extension of BNF for graphical modelling languages

Seminar: A Calculus of Design Patterns6 Aug Example: The Object Adapter DP In GoF book: Indicate where messages can be sent to rather than a component of the pattern! In general, there can be a set of such methods!

Seminar: A Calculus of Design Patterns7 Aug Formal Spec of the Object Adapter DP

Seminar: A Calculus of Design Patterns8 Aug Example 2: The Composite DP GoF Diagram: In general, there can be many leaves!

Seminar: A Calculus of Design Patterns9 Aug Spec of the Composite DP

Seminar: A Calculus of Design Patterns10 Aug General Definition In general, a design pattern P can be defined abstractly as an ordered pair, where Pr is a predicate on the domain of some representation of software systems. It specifies the structural and behavioural features of the pattern V is a set of declarations of variables free in Pr. It specifies the components of the pattern. Notations: Let V = { v 1 : T 1, …, v n : T n } The semantics of the specification is a ground predicate in the form: v 1 : T 1 … v n : T n. ( Pr ) Spec ( P ) to denote the predicate above, Vars ( P ) for the set of variables declared in V, and Pred ( P ) for the predicate Pr. m P : a design model m conforms to pattern P v i are variables that range over the type T i of software elements.

Seminar: A Calculus of Design Patterns11 Aug Pattern Composition Why compose patterns Patterns are usually to be found composed with each other in real applications In practice: Annotation:Role representation: In graphic diagram Taibis work 2006 pattern composition is a combination of formal statements of structural and behavioural features of patterns Illustrated by an example on how two patterns can be composed Bayley &Zhu, 2008 One DP composition operator with a notion of overlaps, which can be One-to-One overlaps One-to-Many overlaps Many-to-many overlaps

Seminar: A Calculus of Design Patterns12 Aug Example of Pattern Composition

Seminar: A Calculus of Design Patterns13 Aug Overview of Our Approach We define a set of six operators on DPs so that compositions of DPs can be formally represented as expressions Restriction: P Pr P Superposition: P P P Extension: P V Pr P Flatten: P V P Generalisation: P V P Lift: P V P We propose a set of algebraic laws to reason about the equivalence of DP compositions (i.e. expressions)

Seminar: A Calculus of Design Patterns14 Aug Restriction Operator P[c] Let P be a given pattern and c be a predicate defined on the components of P. A restriction of P with constraint c, written as P [ c ], is the pattern obtained from P by imposing the predicate c as an additional condition on the pattern. Formally,

Seminar: A Calculus of Design Patterns15 Aug Example A variant of the Composite pattern in which there is only one leaf can be formally defined as follows. Composite 1 = Composite [ ||Leaves|| = 1 ] called Composite 1 in the sequel

Seminar: A Calculus of Design Patterns16 Aug Superposition Operator P * Q Let P and Q be two patterns. the component variables of P and Q are disjoint, i.e., Vars ( P ) Vars ( Q ) =. Definition: The superposition of P and Q, written P * Q, is a pattern that consists of both pattern P and pattern Q as is formally defined as follows.

Seminar: A Calculus of Design Patterns17 Aug Example The superposition of Composite and Adapter patterns: Composite * Adapter It requires each instance to contain one part that satisfies the Composite pattern and another that satisfies the Adapter pattern. These parts may or may not overlap, The following expression does enforce an overlap, requiring that a class in Leaves of the Composite be the target of an Adapter.

Seminar: A Calculus of Design Patterns18 Aug Extension Operator P# ( V c ) Let P be a pattern, V be a set of variable declarations that are disjoint with P 's component variables, i.e., Vars ( P ) V = c be a predicate with variables in Vars ( P ) V. Definition: The extension of pattern P with components V and linkage condition c, written as P# ( V c ), is defined as follows.

Seminar: A Calculus of Design Patterns19 Aug Flatten Operator P x\ x' Let P be a pattern, Vars ( P )= { x : P ( T ), x 1 : T 1, …, x k : T k }, Pred ( P )= p ( x, x 1,…, x k ), and x' Vars ( P ). Definition: The flattening of P on variable x, written P x\ x', is the pattern that has the following property. where the power set of T We also write P x

Seminar: A Calculus of Design Patterns20 Aug Example The single-leaf variant of the Composite pattern Composite 1 can also be defined as follows. Composite 1 = Composite Leaves \ Leaf

Seminar: A Calculus of Design Patterns21 Aug Notations From the definition, we have the following property. For x 1 x 2 and x 1 x 2, We can overload the operator to a set of component variables Let X be a subset of P's component variables all of power set type, i.e., X={x 1 : P(T 1 ), …, x n : P(T n )} Vars(P), n 1 X'={x' 1, …, x' n } X' Vars(P) =. Notation: P X \ X' to denote P x 1 \ x' 1 … x n \ x' n. We also write P X

Seminar: A Calculus of Design Patterns22 Aug Generalisation Operator P x\x' Let P be a pattern, x Vars(P)={x : T, x 1 :T 1, …, x k :T k }. Definition: The generalisation of P on variable x, written P x\x', is defined as follows. Notation: Similar to the operator, we also write P x, and P X

Seminar: A Calculus of Design Patterns23 Aug Example We can define the Composite pattern as a generalisation of the single-leaf variant Composite 1 : Composite = Composite 1 Leaf \ Leaves

Seminar: A Calculus of Design Patterns24 Aug Lift Operator Let P be a pattern CVars(P)={x 1 :T 1, …, x n : T n }, n>0 OPred(P)=p(x 1, …, x n ). X={x 1, …, x k }, 1 k < n, be a subset of the variables in the pattern. Definition: The lifting of P with X as the key, written P X, is the pattern defined as follows. the existentially quantified class components the remainder of the predicate

Seminar: A Calculus of Design Patterns25 Aug Example

Seminar: A Calculus of Design Patterns26 Aug Example Notation: P[x' := x] : systematically renaming x to x; P[v:= x=y] : the syntactic sugar for P[x=y][v:= x][v:=y]; P[v:= x y]: abbreviates P[x y][v:= x]

Seminar: A Calculus of Design Patterns27 Aug Case Study Goal: to demonstrate the expressiveness of the operators Subjects of the case study: In the GoF book, the documentation for each pattern concludes with a brief section entitled Related Patterns. It compares and contrasts patterns, it makes suggestions for how other patterns may be used with the one under discussion. Example: page 106 of the GoF book A Composite is what the builder often builds''. This can be formally specified as follows. (Builder * Composite) [Product = Component]. Method: to formalise them all as expressions with The operators from this paper Formal logic predicates specifying the patterns in our previous work (Bayley&Zhu 2009)

Seminar: A Calculus of Design Patterns28 Aug Results of The Case Study

Seminar: A Calculus of Design Patterns29 Aug. 2010

Seminar: A Calculus of Design Patterns30 Aug Summary of Case Study Results Five new arrows have been added to the GoF diagram (numbered in bold font) discussed in GoF main text but omitted from its diagram We were able to formalise them Four arrows from the original diagram were not formalised (labelled with asterisks) Composite and Interpreter: is a specialisation relation, which can be formally proved; see (Bayley & Zhu 2007). Decorator and Strategy: is a comparison of the two, not a composition suggestion, Strategy and Template Method: as above. Iterator and Visitor: it is mentioned in GoF only on the diagram, but not expanded upon in the main text. The case study has demonstrated that the operators defined in this paper are expressive to define compositions of design patterns.

Seminar: A Calculus of Design Patterns31 Aug Algebraic Laws of the Operators Let P and Q be design patterns. Definition: (Specialisation relation) Let P and Q be design patterns. Pattern P is a specialisation of Q, written P Q, if for all models m, whenever m conforms to P, then, m also conforms to Q. Definition: (Equivalence relation) Pattern P is equivalent to Q, written P = Q, if P Q and Q P. Lemma: m |= P

Seminar: A Calculus of Design Patterns32 Aug The TRUE and FALSE Patterns Definition: Pattern TRUE is the pattern such that for all models m, m |= TRUE. Pattern FALSE is the pattern such that for no model m, m |= FALSE. Lemma For all patterns P, Q and R, we have that

Seminar: A Calculus of Design Patterns33 Aug Laws of Restriction Let vars(p) denote the set of free variables in a predicate p. For all predicates c, c 1, c 2 such that vars(c), vars(c 1 ) and vars(c 2 ) Vars(P), the following equalities hold.

Seminar: A Calculus of Design Patterns34 Aug Laws of Superposition For all patterns P and Q, we have the following equations. From this and reflexivity of, it follows that superposition is idempotent. TRUE and FALSE are the unit and zero of superposition. Superposition is also commutative and associative

Seminar: A Calculus of Design Patterns35 Aug Laws of Extension Let U be any set of component variables that is disjoint to Vars ( P ), and c 1, c 2 be any given predicates such that vars ( c i ) Vars ( P ) U, i=1,2. Let U and V be any sets of component variables that are disjoint to Vars ( P ) and to each other, c 1 and c 2 be any given predicates vars ( c 1 ) Vars ( P ) U and vars ( c 2 ) Vars ( P ) V.

Seminar: A Calculus of Design Patterns36 Aug Laws of Flattening and Generalisation

Seminar: A Calculus of Design Patterns37 Aug Laws Connecting Several Operators For all predicates c such that vars ( c ) Vars ( P ), For all X Vars ( P ), For all X Vars ( P ) Vars ( Q ), where

Seminar: A Calculus of Design Patterns38 Aug For all sets of variables X such that X vars(P) =, and all predicates c such that vars(c) (Vars(P) X), where For all x Vars(P) such that x : P(T)

Seminar: A Calculus of Design Patterns39 Aug. 2010

Seminar: A Calculus of Design Patterns40 Aug where

Seminar: A Calculus of Design Patterns41 Aug Example of Proving Equivalence (1) We have seen the following as examples of the operators: Composite 1 = Composite [ ||Leaves|| = 1 ] Composite 1 = Composite Leaves \ Leaf Composite = Composite 1 Leaf \ Leaves We can prove that: Composite [ ||Leaves|| = 1 ] = Composite Leaves \ Leaf Composite= (Composite Leaves \ Leaf) Leaf \ Leaves Composite 1 =(Composite 1 Leaf \ Leaves) Leaves \ Leaf

Seminar: A Calculus of Design Patterns42 Aug Proof of Composite [ ||Leaves|| = 1 ] = Composite Leaves \ Leaf For all sets X, we have that ||X||=1 x (X={x}) Therefore, Composite[ ||Leaves||=1] = Composite [ Leaf (Leaves={Leaf}) ] = Composite # (Leaf Leaves={Leaf}) = Composite Leaves \ Leaf

Seminar: A Calculus of Design Patterns43 Aug Example of Proving Equivalence (2) Two ways of composition of the Composite and the Adapter patterns Express the compositions as expressions that consist of the operators Apply the algebraic laws to prove that they are equivalent

Seminar: A Calculus of Design Patterns44 Aug First Way of Composition One of the Leaves in the Composite pattern is the Target in the Adapter pattern. This leaf is renamed as the AdaptedLeaf. Lift the adapted leaf to enable several of these Leaves to be adapted. lift the OneAdaptedLeaf pattern with AdaptedLeaf as the key flatten those components in the composite part of the pattern (i.e. the components in the Composite pattern remain unchanged).

Seminar: A Calculus of Design Patterns45 Aug. 2010

Seminar: A Calculus of Design Patterns46 Aug Second Way of Composition Lift the Adapter with target as the key Superpose it to the Composite patterns We can prove that the two ways are equivalent by applying the algebraic laws.

Seminar: A Calculus of Design Patterns47 Aug Conclusion Work in progress and future work The uses of theorem provers for automated reasoning about the compositions of design patterns The soundness of the algebraic laws The completeness of the algebraic laws