Last week I was posting about TDD and CAB and How to write MVP using TDD. This time I’ll focus on How does TDD helps on programming decoupled components?. I want to thank Gabriel Gonzales who gave me the idea commenting on this other post.

Let’s think about it in terms of a sample:

Suppose that I have Component (A) that uses the Component (B). I’m the developer in charge of the Component (A). The architect of my project has come with a fully detailed list of requirements for Component (A) including interactions with Component (B).

So if I’m doing TDD, I’ll try to map a requirement to a test. Since the requirement is specified for Component (A) the test also should be written on the same way. To write the test in a way that it’s accurated I’ve to be sure that once I implement the code for Component (A) the test will pass. What happens if Component B has a problem or it is wrong implemented. Is my code as bad as Component B since it doesn’t pass the test? How can I ensure that I’m really testing what I’ve written? The problem that we’re facing is depicted below.

Bad testing surface

To provide an answer to the questions above I’ll introduce you a concept: Interface Based Programming.

How does Interface Based Programming helps in this case?
Let’s think what happens if we create an interface for Component (B) [IComponentB] that has the methods and properties that it needs to interact with Component (A). After doing this, I can write the code of Component A to be based on IComponentB instead of the concrete Componet B object. Now what I’ve got is a dependency to an interface instead of to a concrete object.  The picture below displays the change that we’ve introduced.

Introducing the interface

So what? For testing porpoises I can create a new object called MockComponentB that implements the interface IComponentB. When I’m doing the test case I can pass this object to be used instead of concrete Component B. With this way of working we’re introducing another concept that is called Inversion of Control. With Mock Objects (that we’ve created for testing propoises) and the usage of IoC pattern we’ve successfuly decoupled the Component A from Component B. Since a Mock Object is a mimic object (for more info: http://en.wikipedia.org/wiki/Mock_object), the new testing surface that we’ve is depicted below.

Good testing surface

As summary we can say:

  • Once we introduced the Mock and the IoC pattern we’ve decoupled the Component A from Component B
  • The surface of our test will have an accuracy of 100% of what we’re testing is really Component A.
  • Working with the idea of minimizing the test surface leaded us to decouple our componets.
  • Working in this way will lead us to have more decoupled component that takes our software to a modular approach where each component has an specific role or responsibility and also it could be exchanged with a new one or better one.

I hope this sample and this post helps you understanding how TDD will help you on programming decoupled components. One thing to have in mind is that making an abuse (for instance having a component for each method of the class or things like that) will take you from decoupling to over engineering.

Questions, feedback and comments are always welcomed.

“This post is in memory of my grandfather who taught me how to do the walk of life “

thanks,
~johnny

Today we’ve released an updated version of DinnerNow, it’s the v1.2. Most of the fixes and improvements that we’re delivering in this oportunity are related to setup and configuration.

Also we’re delivering a couple of new features:

Live Service Tracer Viewer. We’ve taken the version of the Live Service Trace Viewer (WPF & WCF) that was developed by Vittorio Bertucci and Craig McMurtry and make it .NET 3.0 RTM compliant. Also we’ve embedded that functionality into MMC console.

Out-Workflow. David has developed a formatter for PowerShell that is used in our CmdLet to display the workflow status in a graphical version of it. It does a preview of the workflow status using a Control that’ve done like the workflow designer.

CardSpace. We added the support for Custom Claims for the Card Space Sample in out application. Also you can reuse those claims in the check out process to choose the delivery address.

For those who still not beign familiar with DinnerNow.net this is a short description of it.

What’s DinnerNow.net?

DinnerNow.net is a Sample Application that shows how you can develop connected application using several new Microsoft Technologies.

DinnerNow is a ficticious market place where you can order food from different vendors to be delivered at home or office. You can choose the type of food you want (Breakfast, Lunch, Dinner, Meal)

The sample uses most of the lastest Microsoft techologies including: IIS7, ASP.NET AJAX Extensions, LINQ, WCF, WPF, WF, Windows PowerShell, Windows Vista Gadgets, .net Compact Framework and so on. Let's Dinnernow

C’mon get the bits right now! http://www.codeplex.com/DinnerNow

For more information please vist the official web site (http://www.dinnernow.net) and/or team members blogs: James Conard & David Aiken.

Do you want to become an architect? Visit SkyCrapr blogss, you’re a click away from start your path.

thanks
~johnny

Hi guys, I’m proud to announce that today at 7 p.m. DinnerNow.net got its golden build.

What’s DinnerNow.net?

DinnerNow is a sample application that demonstrates all the latest technologies that Microsoft has lunched this FY07. It goes from IIS7 to LINQ, from Powershell to Windows Vista Gadgets. It’s a really cool sample application.

What’s the difference between DinnerNow and other sample apps?

Well, DinnerNow it’s different, it’s a shift in the way that Microsoft develops sample apps. We didn’t just to show features and technologies we want to make it real. We want an Enterprise Scenario where people are aware of latest technologies but they don’t have the SDK Scenario types where everything is cool and you can use the best features of each technology. We’ve made a switch we want the technology to be a tool, to interact, to be part of the thing instead of being the thing.

What’s cool about DinnerNow.net?

It’s an endless thing, we shipped v1.0 but tomorrow we’ll be working on v2.0. We want you to send feedback, report bugs, collaborate and suggest what can be cool to do. This sample is not something common; if you are a Dev you can see how the code has been done, and all the development tasks. If you’re an IT Pro, just check that we’re using Powershell, MMC, and a lot of things to monitor and operate the app. DinnerNow.net it’s out and it’s for everybody!

What you will found when you download it?

DinnerNow.net has been written by really talented people, apart from latest technologies best practices you’ll get reusable code that you can use for your own apps. For example you’ll see lots of Powershell samples, how to write an IIS7 handler, how to use WCF with MSMQ. Also you’ll find our dependency checker, written by David Aiken, which can adds value to whatever you do. How many times you suffer the pain of getting errors on an application because the right components weren’t installed, now you’ll see how to perform that check. There’s a lot of stuff you just have to download it, and start the research :).

The DinnerNow.net Team

I want to write a paragraph special for these guys. Man, it has been one of the greatest projects that I’ve shared with such talented people. Everybody in the DinnerNow.net Team it’s a guru. It’s been really team work, and also we were all committed to get it. I really enjoy working on it.  Also I want to thank everybody on the team for being so polite and for letting me contribute as I can. When you work with people that are open to new ideas, it’s one of the best things that you can experience.

So you’ve read all these lines and didn’t get the code… Man, what are you waiting for? Get it now!

Ohh, I forget to say who is on the Dinnernow.net Team

Please feel free to contribute on our codeplex site, reporting bugs, making constructive suggestions and reporting issues. We expect you to be part of it.

This is the funny ship it picture :)

dinnernow32  

thanks,
~johnny