XPDays Ukraine: Legacy
description
Transcript of XPDays Ukraine: Legacy
![Page 1: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/1.jpg)
Refactoring: Legacy
![Page 2: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/2.jpg)
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
![Page 3: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/3.jpg)
What is...
Short Name DescriptionThe 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.
![Page 4: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/4.jpg)
Rewrite or refactor?
![Page 5: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/5.jpg)
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
![Page 6: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/6.jpg)
Customer vs Developer
Be Honest
Be a Friend
Do Care
Trust
![Page 7: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/7.jpg)
Silly equals
Budget + Time Code + Time=Ignorance Risks=
Business Needs Tech Needs=
![Page 8: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/8.jpg)
#1. Build procedure
Target Oriented Model
Each build script is unique
Low-level build instructions
No use of project information
Build flow or process issues
Project Oriented Model
Every script looks like others
High-level goals
Reuse of project information
Predefined build flow
![Page 9: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/9.jpg)
#2. Inversion of control
Reasons
Reduce coupling.
Increase testability.
Makes further integration easier.
Everybody use it.
![Page 10: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/10.jpg)
Attach IoC library
It is FREE!
![Page 11: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/11.jpg)
XSLT
RegEx
Shell
Java
C#
Python
Etc
Etc
Etc
![Page 12: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/12.jpg)
XSLT: Source
<struts-config>…<action-mappings>…<action path="/logon" type="example.LogonAction"> <forward ... /> <exception ... /></action>
<action type="example.LogoutAction" path="/logout"/>…</action-mappings>…</struts-config>
![Page 13: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/13.jpg)
XSLT: Template
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/"> <beans> <xsl:apply-templates select="struts-config/action-mappings/*"/> </beans></xsl:template><xsl:template match="action"> <bean id="{@path}" class="{@type}"/></xsl:template>
</xsl:stylesheet>
![Page 14: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/14.jpg)
XSLT: Result
<beans>
...
<bean id="/logon" class="example.LogonAction"/>
<bean id="/logout" class="example.LogoutAction"/>
...
</beans>
![Page 15: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/15.jpg)
New code
#3. Fortify defence line
Wall Old code
![Page 16: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/16.jpg)
RegEx: Source
public class UserQuery {...public static User getUser(String userName) {…}
/** JavaDoc */private static void doSomething(Object obj) {…}
/** JavaDoc */public static void saveUser(User user) throws MagicError {…}...}
![Page 17: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/17.jpg)
RegEx: Interface introduction
(?ms)(public\s+static\s+([^{]+).*?)(?=\s+public\s+|\}\s+\z)
public class UserQuery {...User getUser(String userName);
void saveUser(User user) throws MagicError;...}
![Page 18: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/18.jpg)
RegEx: Delegate methods 1
void\s+(\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);}...}
![Page 19: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/19.jpg)
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);}...}
![Page 20: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/20.jpg)
Integration Steps
Attach IoC container.
Convert a couple of similar classes.
Develop a concept.
Share it with the team.
![Page 21: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/21.jpg)
#4. Transaction management
Programmatic
Full control
Low scalability
Noise in code
High mistakes probability
Declarative
Limited control
High scalability
Clean code
Rare mistakes
![Page 22: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/22.jpg)
TransactionManager
Shall be only one ruler
rollbackcommitbegin
![Page 23: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/23.jpg)
Programmatic TM Declarative TM
rollback
commit
begin Data Access Tier
Service Tier
UI Controller Tier
![Page 24: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/24.jpg)
Programmatic TM Declarative TM
rollback
commit
begin get
![Page 25: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/25.jpg)
Programmatic TM
Still Working?
![Page 26: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/26.jpg)
Epilogue
Developer + Customer = Trust
Do you really want it?
Just DO it
Small steps
Problems only
![Page 27: XPDays Ukraine: Legacy](https://reader033.fdocuments.net/reader033/viewer/2022060118/5588f6d1d8b42a974e8b458d/html5/thumbnails/27.jpg)