












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
A series of lecture notes from a university course on software engineering at sharif university of technology. The notes cover the topic of refactoring patterns, including definitions, benefits, and symptoms of bad code. The document also introduces various refactoring patterns and categories, such as composing methods, moving features between objects, and dealing with generalization. Students will find this document useful for understanding the concepts of refactoring and how to improve the design of existing code.
Typology: Slides
1 / 20
This page cannot be seen from the preview
Don't miss anything!













1
Sharif University of Technology
^ The observable behavior of the software should not bechanged.
2
Sharif University of Technology
^ When Should You Refactor? ^ When
Should You Refactor?
^ Refactor the third time you do something similar (The Rule ^ Refactor
Refactor When You Add Function Refactor When You Need to Fix a Bug Refactor As You Do a Code Review
4
Sharif University of Technology
1.^ Duplicated Code2.^ Long Method3.^ Large Class
g
4.^ Long Parameter ListDi
t Ch^
Wh^
l^ i^
l^ h^
d i^ diff
t
5.^ Divergent Change:
When one class is commonly changed in different
ways for different reasons. 6 Shotgun Surgery:
When every time you make a kind of change
you
6.^ Shotgun Surgery:
When
every time you make a kind of change, you
have to make a lot of little changes to a lot of different classes. 7 Feature Envy:
A method that seems more interested in a class other than
7.^ Feature Envy:
A^ method that seems more interested in a class other than the one it actually is in. 8 Data Clumps:
Bunches of data that regularly appear together
5
Sharif University of Technology
8.^ Data Clumps:
Bunches
of data that regularly appear together.
16 Middle Man:
Excessive delegation
16.^ Middle Man:
Excessive
delegation.
17.^ Inappropriate Intimacy:
Excessive interaction and coupling.
18.^ Alternative Classes with Different Interfaces:
Classes that do the
same thing but have different interfaces for what they do. 19. Incomplete Library Class20. Data Class:
Classes that have fields, getting and setting methods for the fields, and nothing else. 21. Refused Bequest:
When subclasses do not fulfill the commitments of
h^
l their superclasses. 22. Comments:
When comments are used to compensate for bad code.
7
Sharif University of Technology
8
Sharif University of Technology
^ Inline Method^ ^
A method
's body is just as clear as its name
^ A method s body is just as clear as its name. ^ Put the method's body into the body of its callers and remove the method. Department of Computer Engineering
10
Sharif University of Technology
^ Replace Method with Method Object^ ^
You have a long method that uses local variables in such a way that you cannot You^ have a long method that uses local variables in such a way that you cannotapplyExtract Method. Turn the method into an object so that all the local variables become fields onthat object
It can then be decomposed into other methods on the same object that object. It can then be decomposed into other methods on the same object.
11
Sharif University of Technology
^ Move Field^ ^
A field is, or will be, used by another class more than the class on which it isdefined. Create a new field in the target class, and change all its users.
13
Sharif University of Technology
^ Extract Class^ ^
You have one class doing work that should be done by two. Create a new class and move the relevant fields and methods from the old class Create a new class and move the relevant fields and methods from the old classinto the new class.
14
Sharif University of Technology
^ Hide Delegate
g
^ A client is calling a delegate class of an object. ^ Create methods on the server to hide the delegate. Department of Computer Engineering
16
Sharif University of Technology
Patterns in Software Engineering – Lecture 10 Moving Features Between Objects:
g^
j
^ Remove Middle Man^ ^
A class is doing too much simple delegation. Get the client to call the delegate directly.
17
Sharif University of Technology
19
Sharif University of Technology
20
Sharif University of Technology