About Me – Frank Xu • Education ▫ North Dakota State University Ph.D. in Software Engineering ▫ Towson University MS in Computer Science ▫ Southeast Missouri State University BS in Computer Science, Minor in Math • Working Experience ▫ GE Transportation, 2008- present, Consultant ▫ Gannon University, 2008- present Director of Keystone Software Development Institute, Assistant Professor of SE ▫ University VA –Wise, 2007- 2008 Assistant Professor of Software Engineering ▫ Swanson Health Products, MIS department, 2005 ~ 2007 Sr. Programmer Analyst ▫ Volt Information Science Inc., 2004 ~ 2005 Software Engineer
About Me – Frank Xu. Education North Dakota State University Ph.D. in Software Engineering Towson University MS in Computer Science Southeast Missouri State University BS in Computer Science, Minor in Math Working Experience GE Transportation, 2008- present, Consultant - PowerPoint PPT Presentation
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
About Me – Frank Xu• Education
▫ North Dakota State University Ph.D. in Software Engineering
▫ Towson University MS in Computer Science
▫ Southeast Missouri State University BS in Computer Science, Minor in Math
• Working Experience▫ GE Transportation, 2008- present,
Consultant▫ Gannon University, 2008- present
Director of Keystone Software Development Institute, Assistant Professor of SE▫ University VA –Wise, 2007- 2008
Assistant Professor of Software Engineering▫ Swanson Health Products, MIS department, 2005 ~ 2007
Sr. Programmer Analyst ▫ Volt Information Science Inc., 2004 ~ 2005
Software Engineer
Refactoring- A disciplined approach to rework for better design.
Objectives•What is refactoring?•Why should I refactor? •When should I refactor?•How to refactor?
Definition•Refactoring is a disciplined technique for
restructuring an existing body of code, ▫altering its internal structure ▫without changing its external behavior.
• It makes the software easier to understand and cheaper to modify.
A simple example•Example: compute gravitational potential energy
▫A class has a numeric type code that does not affect its behavior.
•Refactoring: Replace type code with class ▫Replace the number with a new class.
Person
O: intA: intB:intAB:int
BloodType
O: BloodTypeA: BloodTypeB: BloodTypeAB: BloodType
bloodType:int
public class Person{ …… int bloodType =BloodType.O; …….}
public class BloodType{ public static final int O 1; public static final int A 2; public static final int B 3; public static final int AB 4;}
public enum BloodType { O,A,B,AB}
Inappropriate Intimacy – (1)•Two classes are overly entertwined
▫Sharing of secrets between classes▫Leads to data coupling
•Refactorings▫Hide delegate▫Replace inheritance with delegation
What is problem? Change to Delegate will propagate to the
cleint
Inappropriate Intimacy – (2)•Motivation
▫A client is calling a delegate class of an object.•Refactoring: Hide delegate
▫Create methods on the server to hide the delegate.
Client Server
Delegate
taskA() taskA()
public void method(){ delegate.taskA();}
Client Delegate
taskA()
Inappropriate Intimacy – (3)
ClientClass
Employee
Department
getDepartment() getManager()
public class Department{ private Employee manager; …… public Department (Employee manager){ this.manager=manager; } public string getManager(){ return manager; } …..}
manager=john. Object need to know less about other parts of the
system
public getManager(){ return department.getManager();}
getManager()
getDepartment().
getManager();
Inappropriate Intimacy – (3)• Motivation
▫ A subclass uses only part of a superclasses interface or does not want to inherit data.
• Refactoring: Replace inheritance with delegation▫ Create a field for the superclass, adjust methods to delegate to the
superclass, and remove the subclassing.
Middle Man• Smell
• A method's body is just as clear as its name • Refactoring
▫ Put the method's body into the body of its callers and remove the method
int getRating() { return (moreThanFiveLateDeliveries()) ? 2 :