Software Engineering Refactoring Patterns: Lecture 12 Study Guide by Sharif University, Slides of Software Engineering

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

2011/2012

Uploaded on 02/19/2012

hester
hester 🇮🇷

4.5

(13)

84 documents

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Patterns in
Software Engineering
Lecturer: Raman Ramsin
Lecture 12
Refactoring Patterns
Part 3
Department of Computer Engineering 1Sharif University of Technology
Part
3
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Software Engineering Refactoring Patterns: Lecture 12 Study Guide by Sharif University and more Slides Software Engineering in PDF only on Docsity!

Patterns in Software Engineering Lecturer: Raman Ramsin^ Lecture 12^ Refactoring Patterns

Part 3

1

Sharif University of Technology

Part

Patterns in Software Engineering – Lecture 12 Dealing with Generalization:

Pull Up Constructor Body

Dealing

with Generalization:

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

Patterns in Software Engineering – Lecture 12 Dealing with Generalization:

Extract Interface

Dealing

with Generalization:

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

Patterns in Software Engineering – Lecture 12 Dealing with Generalization:

Collapse Hierarchy

Dealing

with Generalization:

Collapse

Hierarchy

„^

Collapse Hierarchy „^

Collapse

Hierarchy

^ A superclass and subclass are not very different. ^ Merge them together.

5

Sharif University of Technology

Patterns in Software Engineering – Lecture 12 Dealing with Generalization:

Form Template Method

Dealing

with Generalization:

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 Big Refactorings:

Tease Apart Inheritance

Big

Refactorings:

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

once.

Create two hierarchies and use delegation to invoke onefrom the other.

10

Sharif University of Technology

Patterns in Software Engineering – Lecture 12 Big Refactorings:

Tease Apart Inheritance

Big

Refactorings:

Tease

Apart Inheritance 11

Sharif University of Technology

Patterns in Software Engineering – Lecture 12 Big Refactorings:

Convert Procedural Design to Objects

Big

Refactorings:

Convert

Procedural Design to Objects 13

Sharif University of Technology

Patterns in Software Engineering – Lecture 12 Big Refactorings:

Separate Domain from Presentation

Big

Refactorings:

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

Patterns in Software Engineering – Lecture 12 Big Refactorings:

Extract Hierarchy

Big

Refactorings:

Extract

Hierarchy 16

Sharif University of Technology

Patterns in Software Engineering – Lecture 12 R fReference „ Fowler, M.,

Refactoring: Improving the Design of Existing Code,

Addison-Wesley, 1999.

17

Sharif University of Technology