Refactoring code in .net - Các kĩ thuật Refactoring code trong .NET. Đây là một kỹ thuật không thể thiếu nếu các bạn muốn các dòng code của mình ngày một trong sáng, dễ hiểu hơn, clean hơn. Đặc biệt đây là một kỹ thuật không thể thiếu nếu bạn muốn áp dụng Agile/Extreme Programming với Unit Test.
http://tungnt.net/meetup-ve-cac-ky-thuat-refactoring-code-trong-net/
2. About me
• Nguyen Thanh Tung
• Software architect at MISA JSC
• Microsoft Certified Professional Developer
• Technologies:
• Windows/Windows Phone
• ASP.NET
• XAML/Silverlight
• Windows Forms
• …
• Blog at: http://tungnt.net
• Facebook Page: https://www.facebook.com/tungnt185
• Meetup group: http://www.meetup.com/Ha-Noi-NET-Meetup/
3. http://tungnt.net
Table of contents
• Refactoring General
– What is refactoring?
– Who will refactor code?
– Why we need refactor code?
– When to refactor code?
– Where to refactor code?
• How to refactor code?
7. http://tungnt.net
Why we need refactor code?
• Code constantly changes and its quality
constantly degrades (unless refactored)
• Requirements often change and code needs
to be changed to follow them
8. http://tungnt.net
When to refactor code?
• Bad smells in the code indicate need of refactoring
• Refactor when you
– Add a new method or class
– Fix an existing bug
– Reviewing someone else’s code
– Implement TDD (Test-Driven-Development)
• Unit tests guarantee that refactoring does not change the
behavior
– If there are no unit tests, write them
9. http://tungnt.net
Where to refactor code?
• Code smells - certain code structures have possibility of refactoring
• Types of code smells:
• Duplicated code
• Long method
• Large class
• Long parameter list
• Switch statements
• Improper naming
• Data members are public
• …