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
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An overview of refactoring patterns in software engineering as discussed in lecture 12 at sharif university of technology. Topics include dealing with generalization through techniques like pull up constructor body, extract subclass/superclass, extract interface, collapse hierarchy, form template method, replace inheritance with delegation, replace delegation with inheritance, tease apart inheritance, and convert procedural design to objects. Fowler's 'refactoring: improving the design of existing code' is recommended for further study.
Typology: Slides
1 / 17
1
Sharif University of Technology
Pull Up Constructor Body
Pull
Up Constructor Body
^
Pull Up Constructor Body^ ^
You have constructors on subclasses with mostly identical bodies. Create a superclass constructor; call this from the subclass methods.
2
Sharif University of Technology
Extract Subclass/Superclass
Extract
Subclass/Superclass
^
Extract Subclass^
class has features that are used only in some instances.
y
^ Create a subclass for that subset of features. Extract Superclass
^
Extract
Superclass
^ You have two classes with similar features. ^ C e te
^ Create a superclass and move the common features to thesuperclass.
3
Sharif University of Technology
Extract Interface
Extract
Interface
^
Extract Interface^ ^
Several clients use the same subset of a class's interface, or two classes havepart of their interfaces in common. Extract the subset into an interface.
4
Sharif University of Technology
Collapse Hierarchy
Collapse
Hierarchy
^
Collapse Hierarchy ^
Collapse
Hierarchy
^ A superclass and subclass are not very different. ^ Merge them together.
5
Sharif University of Technology
Form Template Method
Form
Template Method
^
Form Template Method^
You have two methods in subclasses that perform similarsteps in the same order, yet the steps are different.
p^
, y
p
^ Get the steps into methods with the same signature, so that ^ Get the steps into methods with the same signature, so thatthe original methods become the same. Then you can pullthem up.
6
Sharif University of Technology
Form Template Method
Form
Template Method
7
Sharif University of Technology
Patterns in Software Engineering – Lecture 12 Dealing with Generalization:
Replace Inheritance with Delegation
g^
p^
g
^
Replace Inheritance with Delegation p^
g
^ A subclass uses only part of a superclass’s interface or does not want to inheritdata. ^ Create a field for the superclass
adjust methods to delegate to the superclass
^ Create a field for the superclass, adjust methods to delegate to the superclass,and remove the subclassing.
8
Sharif University of Technology
Patterns in Software Engineering – Lecture 12 Dealing with Generalization:
Replace Delegation with Inheritance
g^
p^
g
^
Replace Delegation with Inheritance ^
Replace
Delegation with Inheritance
^ You're using delegation and are often writing many simple delegations for theentire interface. ^ M k
th
d l
ti^
l
b l^
f th
d l
t
^ Make the delegating class a subclass of the delegate.
9
Sharif University of Technology
Tease Apart Inheritance
Tease
Apart Inheritance
^
Tease Apart InheritanceTease
Apart Inheritance
^ You have an inheritance hierarchy that is doing two jobs at ^ You
have an inheritance hierarchy that is doing two jobs at
Create two hierarchies and use delegation to invoke onefrom the other.
10
Sharif University of Technology
Tease Apart Inheritance
Tease
Apart Inheritance 11
Sharif University of Technology
Convert Procedural Design to Objects
Convert
Procedural Design to Objects
^
Convert Procedural Design to Objects ^
Convert
Procedural Design to Objects
^ Yo
ha e code
itten in a p oced
al st le
^ Yo
u have code written in a procedural style.
^ T
12
Sharif University of Technology
Convert Procedural Design to Objects
Convert
Procedural Design to Objects 13
Sharif University of Technology
Separate Domain from Presentation
Separate
Domain from Presentation
^
Separate Domain from Presentation ^
Separate
Domain from Presentation
^ You have GUI classes that contain domain logic. ^ Separate the domain logic into separate domain classes.
14
Sharif University of Technology
Extract Hierarchy
Extract
Hierarchy
^
Extract Hierarchy^
You have a class that is doing too much work, at least inpa t th o gh man
conditional statements
^ C
15
Sharif University of Technology
Extract Hierarchy
Extract
Hierarchy 16
Sharif University of Technology
Addison-Wesley, 1999.
17
Sharif University of Technology