Reengineering Patterns-Patterns in Software Engineering-Lecture 14 Slides-Computer Engineering, Slides of Software Engineering

Reengineering Patterns, Detecting Duplicated Code, Visualize Code as Dotplots, Redistribute Responsibilities, Move Behavior Close to Data, Eliminate Navigation Code, Split Up God Class, Transform Self Type Checks, Transform Conditionals to Polymorphism, Factor Out State, Factor Out Strategy, Transform Conditionals to Polymorphism, Raman Ramsin, Lecture Slides, Patterns in Software Engineering, Department of Computer Engineering, Sharif University of Technology, Iran.

Typology: Slides

2011/2012

Uploaded on 02/19/2012

hester
hester ๐Ÿ‡ฎ๐Ÿ‡ท

4.5

(13)

84 documents

1 / 26

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Patterns in
Software Engineering
Lecturer: Raman Ramsin
Lecture 14
Reengineering Patterns
Part 2
Department of Computer Engineering 1Sharif University of Technology
Part
2
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a

Partial preview of the text

Download Reengineering Patterns-Patterns in Software Engineering-Lecture 14 Slides-Computer Engineering and more Slides Software Engineering in PDF only on Docsity!

Patterns in Software Engineering Lecturer: Raman Ramsin^ Lecture 14^ Reengineering Patterns

Part 2

Department of Computer Engineering

1

Sharif University of Technology

Part^

Patterns in Software Engineering โ€“ Lecture 14 Reengineering Patterns:

Detecting Duplicated Code

Reengineering

Patterns:

Detecting Duplicated Code

Department of Computer Engineering

2

Sharif University of Technology

Patterns in Software Engineering โ€“ Lecture 14 Detecting Duplicated Code:

Visualize Code as Dotplots

g^

p^

p

ย„^ Problem:

How can you gain insight into the scope and nature Problem:

How^

can you gain insight into the scope and nature of code duplication in a software system? ย„ Solution:

Visualize the code as a matrix in which the two axes represent two source code files (possibly the same file):represent two source code files (possibly the same file):^ ^ dots in the matrix occur where source code lines are duplicated.Department of Computer Engineering

4

Sharif University of Technology

Patterns in Software Engineering โ€“ Lecture 14 Visualize Code as DotplotsVisualize

Code as Dotplots

Department of Computer Engineering

5

Sharif University of Technology

Patterns in Software Engineering โ€“ Lecture 14 Redistribute Responsibilities:

Move Behavior Close to Data

p

P^ bl

H

d^

f^

l^ f^

b i

ย„^ Problem:

How do you transform a class from being a mere data container into a real service provider? ย„ Solution:

Move behavior defined by indirect clients to the t i^

f th^ d t

hi h it

t

container of the data on which it operates.Department of Computer Engineering

7

Sharif University of Technology

Patterns in Software Engineering โ€“ Lecture 14 Move Behavior Close to DataMove

Behavior Close to Data

Department of Computer Engineering

8

Sharif University of Technology

Patterns in Software Engineering โ€“ Lecture 14 Eliminate Navigation CodeEliminate

Navigation Code

Department of Computer Engineering

10

Sharif University of Technology

Patterns in Software Engineering โ€“ Lecture 14 Redistribute Responsibilities:

Split Up God Class

p^

p^ p

ย„^ Problem:

How do you maintain a class that assumes tooibiliti

many responsibilities? ย„ Solution:

Incrementally redistribute the responsibilities of the god class either to its collaborating classes or to new classesthat are pulled out of the god class.^ ^ When there is nothing left of the god class but a facade, remove ord^

t^ th^ f

d deprecate the facade. Department of Computer Engineering

11

Sharif University of Technology

Patterns in Software Engineering โ€“ Lecture 14 Reengineering Patterns:

Transform Conditionals to Polymorphism

g^

g^

y^ p

Department of Computer Engineering

13

Sharif University of Technology

Patterns in Software Engineering โ€“ Lecture 14 Transform Conditionals to Polymorphism:

Transform Self Type Checks y^ p

yp

ย„^ Problem:

A class is hard to modify or extend because

y

^ it bundles multiple possible behaviors in complex conditional statementsthat test some attribute representing the current "type" of the object. ย„ Solution:

Identify the methods with complex conditional branches ย„^ Solution:

Identify

the methods with complex conditional branches.

In each case:^ ^ Replace the conditional code with a call to a new hook method.p^ ^ Identify or introduce subclasses corresponding to the cases of theconditional.^ ^ In each of these subclasses, implement the hook method with the codecorresponding to that case in the original case statement.Department of Computer Engineering

14

Sharif University of Technology

Patterns in Software Engineering โ€“ Lecture 14 Transform Conditionals to Polymorphism:

Transform Client Type Checks y^ p

yp

ย„^ Problem:

Reducing the coupling between clients and providers of ย„^ Problem:

Reducing

the coupling between clients and providers of

services, where the clients^ ^ explicitly test the type of providers, and^ ^ have the responsibility to compose providers' code. ย„ Solution:^ ^ Introduce a new method into the provider hierarchy.^ ^ Implement the new method in each subclass of the provider hierarchyby moving the corresponding case of the client's conditional to thatclass.^ ^ Replace the entire conditional in the client by a simple call to the newmethod.Department of Computer Engineering

16

Sharif University of Technology

Patterns in Software Engineering โ€“ Lecture 14 Transform Client Type ChecksTransform

Client Type Checks

Department of Computer Engineering

17

Sharif University of Technology

Patterns in Software Engineering โ€“ Lecture 14 Factor Out StateFactor

Out State

Department of Computer Engineering

19

Sharif University of Technology

Patterns in Software Engineering โ€“ Lecture 14 Transform Conditionals to Polymorphism:

Factor Out Strategy y^ p

gy

ย„^ Problem:

How do you make a class whose behavior dependsi h^

l^ f

i bl

ibl?

on testing the value of some variable more

extensible?

ย„^ Solution:

Apply the

Strategy pattern, that is,

^ encapsulate the algorithmic dependent behavior into separate objects ^ encapsulate the algorithmic dependent behavior into separate objectswith polymorphic interfaces, and ^ delegate calls to these objects.Department of Computer Engineering

20

Sharif University of Technology