Decoupling Your Code, By Example
Let’s just say, for arguments sake, that you’ve run across a piece of code that is tightly coupled, i.e. there are lots of hard links between classes, it’s hard to test, changes are difficult, the code breaks when it shouldn’t, etc. Let’s also say, for arguments sake, that you want to improve the design of that code and make it somewhat more maintainable so that you don’t spend the rest of your natural life trying to keep the code from completely falling apart.
How would you do that?
In this screen cast I’ll walk through a sample application, show where the tight coupling occurs and how to remove it. In the process I’ll also be cover a bit of unit testing vs integration testing, mock frameworks, and inversion of control containers (Unity in this case).
Hopefully you get some value from it.
Download the WMV (93Mb, 44mins)
Double click for full screen
References:
- Unity v1.2 - http://codeplex.com/unity
- Rhino Mocks - http://ayende.com/projects/rhino-mocks.aspx
- Alt.Net – http://ozalt.net
- MSTest was used for unit testing
- Readify (a plug for my employer) – http://www.readify.net
For those interested in the Visual Studio add-ons they saw, I am using:
- ReSharper - http://www.jetbrains.com/resharper/
- TestDriven.Net - http://www.testdriven.net
Finally, the video is hosted at http://silverlight.live.com.