+ All Categories
Home > Documents > Banaras Hindu University -...

Banaras Hindu University -...

Date post: 22-Jul-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
47
Banaras Hindu University
Transcript
Page 1: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Banaras Hindu University

Page 2: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

A Course on

Software Reuse by Design Patterns and Frameworks

Page 3: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

by

Dr. Manjari Gupta Department of Computer Science

Banaras Hindu University

Page 4: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Lecture 7

Issues and Challenges in Design Pattern Detection

Page 5: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

∗ not only beneficial to the forward engineering process

∗ patterns can also indicate the design rationale behind the system’s implementation

∗ can aid in code comprehension

Design Pattern Detection

Page 6: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

∗ no support for documenting the presence and usage of patterns in code

∗ reflect the designers’ intents ∗ ongoing research into correlations between the use of

Design Patterns and defect frequency ∗ Design document is often missing in many legacy

systems ∗ helps on program comprehension and design

visualization ∗ Code maintenance would be made easier

Importance of Design Pattern Detection

Page 7: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

∗ should automatic ∗ should detect nonstandard implementations of design

patterns along with their standard implementations ∗ should fast ∗ should not specific to few particular design patterns. ∗ should be customizable ∗ should detect as less number of false positive and false

negative patterns as possible.

Important features of a method for detecting Design Patterns

Page 8: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

∗ executable code- static and dynamic analyses, ∗ documentation of source codes, ∗ design model (UML designs) and ∗ other specifications.

Product used for DPD

Page 9: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

∗ must accurately reflect the traits of each pattern ∗ Must differentiate one pattern from other patterns ∗ strictness of definition ∗ more redundancy in a pattern’s definition, the

more false positives ∗ formal design patterns definition is required

Design Pattern Definition

Page 10: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

∗ based on the decomposition approach. ∗ getting idea about EDPs or meta patterns ∗ Design patterns are expressed exclusively through EDPs ∗ Hayashi et al [Hayashi08] used Pree’s meta patterns to

represent these common properties ∗ checked if the pre-defined conditions of the design pattern,

including the combination conditions of the meta patterns, hold or not.

∗ If it fails in this stage, they moved to other patterns that have the same meta patterns. ∗ reduce any redundant repetition of checking meta patterns

Design pattern detection based on their common properties

Page 11: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

∗ pattern detection tools includes three parts ∗ a parser, a detector, and a database.

∗ challenges in pattern detection ∗ the size of the exploration space for large software

systems.

Approaches to detect design patterns

Page 12: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

∗ similarity score algorithm to detect design patterns. ∗ structural relations between classes are encoded in

multiple graphs and matrices. ∗ similarly the design patterns are also encoded in

matrices. ∗ similarity score between the matrices of system

source and those of patterns.

Tsantalis et al. approach

Page 13: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

∗ SPQR ∗ System for Pattern Query and Recognition ∗ developed at the University of Carolina ∗ uses Elemental Design Patterns, a theorem prover

and ρ-calculus to detect DPs.

Tools for DPD

Page 14: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

∗ Fujaba [Niere02] ∗ forward and reverse engineering tool ∗ developed at the University of Paderborn ∗ uses graph matching on abstract syntax graphs

representing source code, combined with fuzzy logic. ∗ treat design and implementation variants of patterns

separately.

Tools for DPD Cont…

Page 15: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

∗ Ptidej [Gueheneuc05] ∗ visual tool for design recovery and DP recognition. ∗ Detection is performed through constraints

satisfaction with explanation

Tools for DPD Cont…

Page 16: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

∗ system and patterns, they can be represented in the form of matrices.

DPD based on only structural and static analysis [Pande10]

Page 17: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Calculation of matrices for system design

Client

AbstractFactory

+CreateProduct()

AbstractProduct

ConcreteFactory ConcreteProduct

Page 18: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Calculation of matrices for system design

Client

AbstractFactory

+CreateProduct()

AbstractProduct

ConcreteFactory ConcreteProduct Direct Association matrix of Fig. 1 (root = 3)

Page 19: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Calculation of matrices for system design

Client

AbstractFactory

+CreateProduct()

AbstractProduct

ConcreteFactory ConcreteProduct Direct Association matrix of Fig. 1 (root = 3)

Dependency matrix Fig. 1 (root = 2)

Page 20: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Calculation of matrices for system design

Client

AbstractFactory

+CreateProduct()

AbstractProduct

ConcreteFactory ConcreteProduct Direct Association matrix Dependency matrix Generalization matrix of Fig. 1 (root = 3) of Fig. 1 (root = 2) of Fig. 1 (root = 5)

Page 21: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Calculation of matrices for system design

Client

AbstractFactory

+CreateProduct()

AbstractProduct

ConcreteFactory ConcreteProduct Direct Association matrix Dependency matrix Generalization matrix of Fig. 1 (root = 3) of Fig. 1 (root = 2) of Fig. 1 (root = 5)

Overall Matrix

Page 22: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Calculation of matrices for Façade design pattern

Facade

Subsystem Classes

Façade Design Pattern

Page 23: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Calculation of matrices for Façade design pattern

Facade

Subsystem Classes

Façade Design Pattern

Direct Association matrix of fig 5 (root = 2)

Page 24: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Calculation of matrices for Façade design pattern

Facade

Subsystem Classes

Façade Design Pattern

Direct Association matrix of fig 5 (root = 2)

Overall Matrix

Page 25: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Calculation of matrices for Façtory Method design pattern

Factory Method Design Pattern

Product

ConcreteProduct

Creator

+FactoryMethod()

ConcreteCreator

Page 26: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Calculation of matrices for Façtory Method design pattern

Factory Method Design Pattern

Product

ConcreteProduct

Creator

+FactoryMethod()

ConcreteCreator

Dependency matrix of fig 2 (root = 3)

Page 27: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Calculation of matrices for Façtory Method design pattern

Factory Method Design Pattern

Product

ConcreteProduct

Creator

+FactoryMethod()

ConcreteCreator

Dependency matrix of fig 2 Generalization matrix of fig 2 (root = 3) (root = 5)

Page 28: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Calculation of matrices for Façtory Method design pattern

Factory Method Design Pattern

Product

ConcreteProduct

Creator

+FactoryMethod()

ConcreteCreator

Dependency matrix of fig 2 Generalization matrix of fig 2 (root = 3) (root = 5)

Overall Matrix

Page 29: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Calculation of matrices for singleton design pattern

Singleton

+Instance(): Singleton -instance

Singleton Design Pattern

Page 30: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Calculation of matrices for singleton design pattern

Singleton

+Instance(): Singleton -instance

Singleton Design Pattern

[ 1 ] Direct Association matrix of fig 5 (root = 2)

Page 31: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Calculation of matrices for singleton design pattern

Singleton

+Instance(): Singleton -instance

Singleton Design Pattern

[ 1 ] Direct Association matrix of fig 5 (root = 2)

[21]

Page 32: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Calculation of matrices for singleton design pattern

Singleton

+Instance(): Singleton -instance

Singleton Design Pattern

[ 1 ] Direct Association matrix of fig 5 (root = 2)

[21]

[2] Overall Matrix

Page 33: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

∗ determine whether a graph is isomorphic to a subgraph of another graph.

∗ is NP-complete. ∗ G1 (V1, E1) and G2 (V2, E2) be two graphs ∗ M1 and M2 be the adjacency matrices ∗ A permutation matrix is a square (0, 1)-matrix ∗ G1 (M1, Lv, Le) and G2 (M2, Lv, Le) are said to be

isomorphic if there exist a permutation matrix P such that

M2 = P M1 PT

Sub-graph isomorphism detection

Page 34: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

∗ Given an n x n matrix M = (mij), let Sk,m(M) denote the k x m matrix that is obtained from M by deleting rows k + 1 , . . . , n and columns m + 1 , . . . , n, where k, m < n.

∗ Let G1 and G2 be graphs with adjacency matrices M1 and M2 of dimensions m x m and n x n respectively, where m < =n. There is a subgraph isomorphism from G1 to G2 if there exists an n x n permutation matrix P such that

M1 = Sm, m (P M2 PT) M2 -system design matrix and M1 -design pattern matrix

Sub-graph isomorphism detection

Page 35: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Design Pattern Detection as Façade Design Pattern

Page 36: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Design Pattern Detection as Façade Design Pattern

P =

Page 37: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Design Pattern Detection as Façade Design Pattern

P = PT =

Page 38: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Design Pattern Detection as Façade Design Pattern

P = PT =

PSPT =

Page 39: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Design Pattern Detection as Façade Design Pattern

P = PT =

PSPT =

After eliminating entries from 3rd row and 3rd column we have reduced matrix as (because Façade Design Pattern is of 2 x 2 order)

Page 40: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Design Pattern Detection as Factory Method Design Pattern

Page 41: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Design Pattern Detection as Factory Method Design Pattern

Page 42: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Design Pattern Detection as Factory Method Design Pattern

Page 43: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Design Pattern Detection as Factory Method Design Pattern

Page 44: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Design Pattern Detection as Factory Method Design Pattern

Page 45: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Design Pattern Detection as Factory Method Design Pattern

After eliminating 5th row and 5th column (since factory method has order 4 x 4),

Page 46: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

∗ For singleton there will be no permutation matrix for which we can find out (after row and column elimination) a matrix which is equivalent to design pattern matrix.

Particular Design Pattern may or may not exist

Page 47: Banaras Hindu University - eacharya.inflibnet.ac.ineacharya.inflibnet.ac.in/.../ET/9-7-ET-V1-S1__ppt7.pdf · * based on the decomposition approach. * getting idea about EDPs or meta

Recommended