Laws of Pattern Composition Hong Zhu and Ian Bayley Department 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

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.
A Calculus of Design Patterns Hong Zhu Dept. of Computing and Electronics Oxford Brookes University Oxford OX33 1HX, Uk
The Game of Algebra or The Other Side of Arithmetic The Game of Algebra or The Other Side of Arithmetic © 2007 Herbert I. Gross by Herbert I. Gross & Richard.
3 Logic The Study of What’s True or False or Somewhere in Between.
Copyright Maveo Systems Shanghai1 Becoming a Good Software Architect By Terry Cheng (郑书玄 ) Chief Technology Officer 万域系统软件(上海)有限公司.
10 October 2006 Foundations of Logic and Constraint Programming 1 Unification ­An overview Need for Unification Ranked alfabeths and terms. Substitutions.
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
Instructor: Hayk Melikya
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
Vocabulary and Properties. Determine the word or phrase described in each slide.
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.
Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page: Lecture.
Discrete Structures Chapter 3 Set Theory Nurul Amelina Nasharuddin Multimedia Department.
1 Section 10.1 Boolean Functions. 2 Computers & Boolean Algebra Circuits in computers have inputs whose values are either 0 or 1 Mathematician George.
EE1J2 - Slide 1 EE1J2 – Discrete Maths Lecture 6 Limitations of propositional logic Introduction to predicate logic Symbols, terms and formulae, Parse.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
1 Set Operations CS/APMA 202, Spring 2005 Rosen, section 1.7 Aaron Bloomfield.
1 Learning Objectives for Section 7.2 Sets After today’s lesson, you should be able to Identify and use set properties and set notation. Perform set operations.
10 May 2009Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Formal.
1. a < b means a is less than b
Set Notation.
This section will discuss the symbolism and concepts of set theory
22 March 2009Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Formal.
Math 3121 Abstract Algebra I Lecture 3 Sections 2-4: Binary Operations, Definition of Group.
©Ian Sommerville 2000Software Engineering, 6th edition. Chapter 9 Slide 1 Formal Specification l Techniques for the unambiguous specification of software.
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.
Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo
Set, Combinatorics, Probability & Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Set,
Chapter 7 Logic, Sets, and Counting Section 2 Sets.
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.
Formal Methods in Software Engineering 1
CompSci 102 Discrete Math for Computer Science
 I can identify and use the properties of real numbers.
Copyright © Cengage Learning. All rights reserved.
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 With Question/Answer Animations. Section 2.1.
Predicates and Quantifiers Dr. Yasir Ali. 1.Predicates 2.Quantifiers a.Universal Quantifiers b.Existential Quantifiers 3.Negation of Quantifiers 4.Universal.
Copyright © Cengage Learning. All rights reserved. CHAPTER 8 RELATIONS.
Module #3 - Sets 3/2/2016(c) , Michael P. Frank 2. Sets and Set Operations.
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.
Introduction to Set Theory (§1.6) A set is a new type of structure, representing an unordered collection (group, plurality) of zero or more distinct (different)
Sets, Permutations, and Combinations. Lecture 4-1: Sets Sets: Powerful tool in computer science to solve real world problems. A set is a collection of.
The Relation Induced by a Partition
Dr. Ameria Eldosoky Discrete mathematics
Relations and Functions
Set, Combinatorics, Probability & Number Theory
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 2 Sets Slides are adopted from “Discrete.
B (The language of B-Method )
2.3 Linear Inequalities Understand basic terminology related to inequalities Solve linear inequalities symbolically Solve linear inequalities graphically.
Copyright © Cengage Learning. All rights reserved.
A Brief Summary for Exam 1
Solving Equations and Inequalities with Absolute Value
Solving Equations and Inequalities with Absolute Value
Chapter 7 Logic, Sets, and Counting
Chapter 6: Formal Relational Query Languages
Copyright © Cengage Learning. All rights reserved.
Predicates and Quantifiers
Presentation transcript:

Laws of Pattern Composition Hong Zhu and Ian Bayley Department of Computing and Electronics Oxford Brookes University Oxford OX33 1HX, Uk

ICFEM 2010, Shanghai2 Nov 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 for pattern instantiation and pattern recovery (e.g. PINOT, Mapelsden et al. 2002)

ICFEM 2010, Shanghai3 Nov 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!

ICFEM 2010, Shanghai4 Nov Pattern Specification A design pattern P can be defined abstractly as an ordered pair, where V = { v 1 : T 1, …, v n : T n } is a set of variable declarations that specify the components of the pattern Pr is a predicate that specifies the structural and behavioural features of the pattern The semantics of the specification: v 1 : T 1 … v n : T n. ( Pr ) Notations: 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.

ICFEM 2010, Shanghai5 Nov Formal Spec of the Object Adapter DP

ICFEM 2010, Shanghai6 Nov Pattern Composition Why compose patterns Patterns are usually to be found composed with each other in real applications How pattern compositions are represented in practice: Annotation:Role representation in graphic diagram

ICFEM 2010, Shanghai7 Nov Example of Pattern Composition

ICFEM 2010, Shanghai8 Nov Formal Approach to DP Composition Define a set of six operators on DPs 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 Represent DP compositions as expressions Prove a set of algebraic laws to reason about the equivalence of DP compositions I. Bayley & H. Zhu, A Formal Language of Pattern Composition, Proc. of PATTERNS 10, Lisbon, Portugal, Nov (In press)

ICFEM 2010, Shanghai9 Nov 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,

ICFEM 2010, Shanghai10 Nov 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.

ICFEM 2010, Shanghai11 Nov 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.

ICFEM 2010, Shanghai12 Nov 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

ICFEM 2010, Shanghai13 Nov 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

ICFEM 2010, Shanghai14 Nov 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

ICFEM 2010, Shanghai15 Nov 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]

ICFEM 2010, Shanghai16 Nov Case Study: Expressiveness of the operators Subject: Compositions of patterns suggested in the GoF book In the sections of Related Patterns in GoF book 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 proposed operators Result: all suggested compositions were successfully expressed in the operators See [Bayley & Zhu: PATTERNS 10]

ICFEM 2010, Shanghai17 Nov 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. m |= P

ICFEM 2010, Shanghai18 Nov 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

ICFEM 2010, Shanghai19 Nov 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.

ICFEM 2010, Shanghai20 Nov 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

ICFEM 2010, Shanghai21 Nov 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.

ICFEM 2010, Shanghai22 Nov Laws of Flattening and Generalisation

ICFEM 2010, Shanghai23 Nov 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

ICFEM 2010, Shanghai24 Nov 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)

ICFEM 2010, Shanghai25 Nov. 2010

ICFEM 2010, Shanghai26 Nov where

ICFEM 2010, Shanghai27 Nov Proving Equivalence: Example 1 Consider the Composite DP: Composite 1 = Composite [ ||Leaves|| = 1 ] Composite 1 = Composite Leaves \ Leaf Composite = Composite 1 Leaf \ Leaves We can prove that: 1. Composite [ ||Leaves|| = 1 ] = Composite Leaves \ Leaf 2. Composite= (Composite Leaves \ Leaf) Leaf \ Leaves 3. Composite 1 =(Composite 1 Leaf \ Leaves) Leaves \ Leaf

ICFEM 2010, Shanghai28 Nov The Composite DP In general, there can be many leaves!

ICFEM 2010, Shanghai29 Nov Proof of Equation (1) Composite [ ||Leaves|| = 1 ] = Composite Leaves \ Leaf Proof. For all sets X, we have that ||X||=1 x (X={x}) Therefore, Composite[ ||Leaves||=1] = Composite [ Leaf (Leaves={Leaf}) ] = Composite # (Leaf Leaves={Leaf}) (Slide 24) = Composite Leaves \ Leaf (Slide 24) QED

ICFEM 2010, Shanghai30 Nov Proving Equivalence: Example 2 Composition of the Composite and the Adapter patterns A subset of leaves in Composite DP are adapted as the targets of Adaptor DP

ICFEM 2010, Shanghai31 Nov 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).

ICFEM 2010, Shanghai32 Nov 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.

ICFEM 2010, Shanghai33 Nov Related Work 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 Defined One DP composition operator with a notion of overlaps, which can be One-to-One overlaps One-to-Many overlaps Many-to-many overlaps

ICFEM 2010, Shanghai34 Nov Work in Progress and Future Work Work in Progress The logic properties of the operators Preserving the soundness, adequacy and semantics of DPs The completeness of the algebraic laws Future work Automated reasoning about pattern compositions

ICFEM 2010, Shanghai35 Nov References 1. Taibi, T.: Formalising design patterns composition. Software, IEE Proceedings 153(3), 126–153 (June 2006) 2. Bayley, I., Zhu, H.: On the composition of design patterns. In: Proc. of QSIC pp.27– 36. IEEE Computer Society, (Aug 2008) 3. Bayley, I. and Zhu, H.: Formal specification of the variants and behavioural features of design patterns. Journal of Systems and Software 83(2), 209–221 (Feb 2010) 4. Bayley, I. and Zhu, H., A formal language of pattern composition. In: Proc. of PATTERNS 2010, Lisbon, Portugal (Nov. 2010) (In Press)