


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 26
This page cannot be seen from the preview
Don't miss anything!



















Department of Computer Engineering
1
Sharif University of Technology
Department of Computer Engineering
2
Sharif University of Technology
Visualize Code as Dotplots
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
Department of Computer Engineering
5
Sharif University of Technology
Move Behavior Close to Data
P^ bl
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
Department of Computer Engineering
8
Sharif University of Technology
Department of Computer Engineering
10
Sharif University of Technology
Split Up God Class
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
Transform Conditionals to Polymorphism
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
Department of Computer Engineering
17
Sharif University of Technology
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
on testing the value of some variable more
ย^ Solution:
Apply the
^ 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