This document discusses refactoring legacy code projects. It begins by introducing the author and their experience with legacy projects. It then describes different types of legacy projects using nicknames. It discusses whether a project should be rewritten or refactored. It lists requirements needed for refactoring a legacy project. It compares a developer and customer perspective. It then provides examples of techniques that can be used when refactoring like building procedures, inversion of control, regular expressions, transaction management, and integrating incremental changes. The overall message is that refactoring legacy projects requires an open mindset, establishing trust between developers and customers, and taking problems step-by-step through small incremental changes.
2. Who am I?
Victor Polischuk
A man with a terrible character.
Java architect, team leader and coach.
8+ years of software development experience.
6+ years of Java experience.
Have participated in 6+ legacy projects.
Have seen numbers of them.
Employed in Luxoft
3. What is...
Short Name Description
The Highlander Old, mature projects, had been written ages
ago. Paragon.
Die Hard Nobody knows why it is still alive.
Fashion Victims Nobody wants this sh%t anymore.
Problem Child Nobody loves it.
Sentenced Customer tired of supporting it, everything is up
to you.
Apathetic Nobody cares.
5. What do we need...
1.A legacy project
2.A team of developers eager to refactor it.
3.A customer convinced enough to pay for it.
4.Smart tools (IDE, RegEx, File Manager etc.)
5.Open mind
7. Silly equals
Budget + Time
= Code + Time
Ignorance
= Risks
Business Needs
= Tech Needs
8. #1. Build procedure
Target Oriented Model Project Oriented Model
Each build script is unique Every script looks like others
Low-level build instructions High-level goals
No use of project information Reuse of project information
Build flow or process issues Predefined build flow
9. #2. Inversion of control
Reasons
Reduce coupling.
Increase testability.
Makes further integration easier.
Everybody use it.
18. RegEx: Delegate methods 1
voids+(w+)s*(((?:(w+)s+(w+),?s*)+))s*;
void $1($2) {UserQuery.$1(<...>);}
public class UserDaoImpl implements UserDao {
...
User getUser(String userName);
void saveUser(User user) {UserQuery.saveUser(user);}
...
}
19. RegEx: Delegate methods 2
(w+)s+(w+)s*(((?:(w+)s+(w+),?s*)+))s*;
$1 $2($3) {return UserQuery.$2(<...>);}
public class UserDaoImpl implements UserDao {
...
User getUser(String userName) {
return UserQuery.getUser(userName);
}
void saveUser(User user) {UserQuery.saveUser(user);}
...
}
20. Integration Steps
Attach IoC container.
Convert a couple of similar classes.
Develop a concept.
Share it with the team.
21. #4. Transaction management
Programmatic Declarative
Full control Limited control
Low scalability High scalability
Noise in code Clean code
High mistakes probability Rare mistakes
22. Shall be only one ruler
TransactionManager
begin commit rollback
23. Programmatic TM Declarative TM
begin Data Access Tier
commit Service Tier
rollback UI Controller Tier