In this presentation we are going to be going through a typical reengineering engagement with a fictional client. We will walk through all the steps necessary to reengineer an existing system from the start to the finish.
There are many reasons to reengineer an existing system. These are only a few. We will talk to our client to find out what are the main reasons for the desire to reengineer their system.
These are the main advantages of reengineering over rewriting.A largely ignored factor is that reengineering retains the unintended side effects of the way the current code was implemented. Customer come to depend on the small artifacts in our software, and if we rewrite it those artifacts will be lost without us knowing it. By keeping as much of the business logic as possible, these artifacts are retained, and customers are kept happy.
We are assuming the project we will be working with is Winforms, and that the unit tests are few and far between.We also assume that our UI will be moving towards ASP MVC and also WPF. Silverlight is in the distant future.Note that we are going to be structuring the system so that all of the UI implementations will use the same business logic – without changes.
First, we analyze the existing code to see what we are up against. This helps us estimate how long the project will take, what infrastructure elements we will need to introduce, and which elements will need to be replaced.
Deciding on a proper unit test framework is an important first step. There are various options depending on various factors in the development environment.
It is best to divide out the integration tests up front since they take so much time to run.Note that training is never done! All new additions must be accompanied by team training to make sure the team adopts the new technology. New infrastructure that nobody uses is worthless.
Nightly builds are must. Builds on each checkin are helpful, but not required.
Code coverage is a very useful tool, helping to measure progress towards complete test coverage.Mocking frameworks can be complicated, so the team should be involved in this decision.
Why Rework a Functioning System?<br />Make it more maintainable<br />Reorganize and update structure<br />Move to a more modern language or platform<br />Modularization<br />Data reengineering<br />Enable Process Reengineering<br />Add new functionality<br />Improve Performance<br />Improved response to required system changes<br />Introduce quality and other measurable improvements<br />Future labor savings (dev team and business team)<br />System Consolidation<br />You can Rewrite or Reengineer<br />Brad Irby - Alobria Systems<br />
Advantages of Reengineering<br />Reduced Customer Impact<br />No Feature Freeze – Plane Stays in the Air<br />Fits well with Agile Release Schedules<br />Reduced Risk<br />Maintains existing business logic, processes, and side effects<br />Fewer errors interpreting existing system<br />Reduced Cost<br />Can use outside talent <br />Business logic already complete<br />Shorter Timeline (about 6-9 months)<br />Continuous QA<br />25% of the cost of a rewrite (Ulrich, 1990)<br />Brad Irby - Alobria Systems<br />
Before We See Code…<br />Assumptions<br />Winforms - Using Adapted Prism<br />Unit Tests are rarely done now<br />UI Requirements<br />Winforms now<br />ASP MVC near future<br />WPF in the medium future<br />Maybe Silverlight in far future<br />Different UI’s But Single Controller<br />Brad Irby - Alobria Systems<br />
Preliminary Code Review<br />Establish validity of MVC<br />Everybody claims it, few have it<br />Count Number of Static Classes<br />Pure constant or enum classes don’t matter<br />Count Activator Calls<br />Count Average Num References per Project<br />Look at validity of references<br />Where is wizard controller logic?<br />Know What You Are Up Against<br />Brad Irby - Alobria Systems<br />
Lay Groundwork (Basics)<br />Decide Unit Test Framework<br />External GUI runner<br />Integrated into VS2008/2010 (TestDriven)<br />Integrates with Code Coverage<br />Integrates with TFS?<br />Has Command Line<br />Reporting with data export<br />Nunit, MbUnit, MSTest<br />Spend the time to do this right<br />Brad Irby - Alobria Systems<br />
Lay Groundwork (Basics)<br />Divide Tests<br />Integration tests<br />Unit tests<br />Install test runner<br />TestDriven or Resharper are good<br />Train Team<br />TestDriven<br />NUnit<br />Training is an ongoing effort<br />Brad Irby - Alobria Systems<br />
Lay Groundwork (Basics)<br />Setup Build Server<br />Nightly build a must<br />Email build Success/Fail<br />Continuous Integration helps a lot<br />Cruise Control and CCTray<br />Nightly runs of integration tests<br />Unit tests run on each checkin<br />Peer Pressure Not To Break Builds<br />Brad Irby - Alobria Systems<br />
Lay Groundwork (Advanced)<br />Decide on Code Coverage<br />NCover or MS Team Coverage<br />Stats should run nightly to develop trend<br />Over time, decide on max Cyclomatic Complexity<br />Decide on Mocking Framework<br />Moq, Rhino mocks, Typemock Isolator (Big Daddy)<br />Ensure data model is in project by itself<br />Allows use from old and new code<br />Get Team Buy-in on these<br />Brad Irby - Alobria Systems<br />
Let’s See Some Code!<br />Project Structure Strategy<br />Preliminary Code Cleanup<br />Remove unneeded Using clauses and References<br />VS PowerCommands for Usings<br />References – brute force<br />Update project target framework<br />Clean up warnings<br />“Warning as Errors”<br />Careful of too many partial classes<br />Code Changes Good for Junior Dev<br />Brad Irby - Alobria Systems<br />
Migrate Infrastructure<br />Add Bootstrapper<br />Establish first 2 modules<br />Shared<br />Smallest and Easiest Module<br />Move Constants and Enums (Jr. Dev)<br />Make these Static classes<br />Look for Static Services classes<br />Difficult to Mock and test (statics are sealed)<br />Cause problems testing other things<br />Search for “public static class”<br />Change to normal class (singleton via container)<br />Need Interface<br />SearchPageFactory<br />Small Changes Can Have Big Effects<br />Brad Irby - Alobria Systems<br />
Migrate Infrastructure<br />Look for singleton patterns<br />Search for “.Instance”<br />Move to Service Locator<br />BusinessObjectCacheManager<br />Look for services with no Interfaces<br />Can move to “everything” interface easily<br />Put in ServiceLocator<br />Watch your References<br />Old to New = OK<br />New to Old = Bad<br />Slowly Move To New Infrastructure<br />Brad Irby - Alobria Systems<br />
Migrate Views & Controllers<br />Start with Easiest<br />Lots of infrastructure needed for first one<br />Don’t complicate with difficult workflow<br />Use views that don’t need data binding if possible<br />Second – easy workflow with data binding<br />Third – most complicated workflow<br />Last – pass patterns on to team for implementation<br />Build Example Patterns for Others<br />Brad Irby - Alobria Systems<br />
Testing Considerations<br />Bootstrapper<br />Add Extension methods to setup mocks<br />Moq lets you get the Mock via an object<br />Make plenty of Mocking examples for others to learn from<br />Try for 75% or more coverage on new code<br />Don’t overload TestSetup<br />Common beginner mistake<br />Unit Tests Difficult for Some<br />Brad Irby - Alobria Systems<br />
Parting Comments<br />Don’t call old code “Legacy”<br />Work closely with QA<br />You will break things that were solid before<br />Copy code to new projects where you can<br />Unit Tests Difficult for Newbs<br />Brad Irby - Alobria Systems<br />