banaras hindu university -...

Post on 22-Jul-2020

1 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Banaras Hindu University

A Course on

Software Reuse by Design Patterns and Frameworks

by

Dr. Manjari Gupta Department of Computer Science

Banaras Hindu University

Lecture 7

Issues and Challenges in Design Pattern Detection

∗ 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

∗ 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

∗ 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

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

Product used for DPD

∗ 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

∗ 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

∗ 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

∗ 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

∗ 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

∗ 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…

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

satisfaction with explanation

Tools for DPD Cont…

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

DPD based on only structural and static analysis [Pande10]

Calculation of matrices for system design

Client

AbstractFactory

+CreateProduct()

AbstractProduct

ConcreteFactory ConcreteProduct

Calculation of matrices for system design

Client

AbstractFactory

+CreateProduct()

AbstractProduct

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

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)

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)

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

Calculation of matrices for Façade design pattern

Facade

Subsystem Classes

Façade Design Pattern

Calculation of matrices for Façade design pattern

Facade

Subsystem Classes

Façade Design Pattern

Direct Association matrix of fig 5 (root = 2)

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

Calculation of matrices for Façtory Method design pattern

Factory Method Design Pattern

Product

ConcreteProduct

Creator

+FactoryMethod()

ConcreteCreator

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)

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)

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

Calculation of matrices for singleton design pattern

Singleton

+Instance(): Singleton -instance

Singleton Design Pattern

Calculation of matrices for singleton design pattern

Singleton

+Instance(): Singleton -instance

Singleton Design Pattern

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

Calculation of matrices for singleton design pattern

Singleton

+Instance(): Singleton -instance

Singleton Design Pattern

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

[21]

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

∗ 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

∗ 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

Design Pattern Detection as Façade Design Pattern

Design Pattern Detection as Façade Design Pattern

P =

Design Pattern Detection as Façade Design Pattern

P = PT =

Design Pattern Detection as Façade Design Pattern

P = PT =

PSPT =

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)

Design Pattern Detection as Factory Method Design Pattern

Design Pattern Detection as Factory Method Design Pattern

Design Pattern Detection as Factory Method Design Pattern

Design Pattern Detection as Factory Method Design Pattern

Design Pattern Detection as Factory Method Design Pattern

Design Pattern Detection as Factory Method Design Pattern

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

∗ 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

top related