There is no single “right way”. However, I really think Test Driven Development (TDD) will help in your case. I believe that writing tests first helps shape the API and makes the code cleaner. When you first write tests, you first think about how the code will be called (the interface or “what should it do”) before thinking about the implementation (“how do I do this”).
For example, imagine creating a CRM module. You might think that the first thing to do is get the client to spend the most money. So you should write a test:
Assert.AreEqual (Customer1, crm.GetMostValuableCustomer (), "the most valuable customer is not as expected");
Then you can do the following:
Assert.AreEqual (new customer [] {Customer1, Customer2, Customer3}, crm.GetCustomerByValue (), "GetCustomersByValue () is not as expected");
So, the point is that you think about the code from a different perspective (as a consumer, not as a producer). I believe that helps me write much cleaner code, and then I don’t need to go back and create regression tests later. I wish I had a better example, but I hope you will see how working with this method can help you in the prototyping phase.
source share