OK, having tried my first TDD attempt, it's time to reflect a little and get some guidance, because it wasn't that successful for me. The solution was partly being made with an existing framework, perhaps making TDD less ideal. The part that seemed to give me the biggest problem, was the interaction between the view and controller. I'll give a few simple examples and hope that someone will tell me what I can do better wrong.
Each view's interface inherits from a base interface, with these members (there are more):
public interface IView
{
void ShowField(string fieldId)
void HideField(string fieldId)
void SetFieldVisibility(string fieldId, bool visible)
void DisableField(string fieldId)
void ShowValidationError(string fieldId)
...
}
The interface for a concrete view, would then add members for each
field like this
public interface IMyView : IView
{
string Name { get; set; }
string NameFieldID { get; }
...
}
What do you think of this? Is inheriting from a common interface a good or bad idea? One on the things that gave me trouble was, that first I used ShowField and HideField and the found out I would rather use SetFieldVisiblity. I didn't change the outcome of the method, but I had to update my test, which I seem should be necessary. Is having multiple methods doing the same thing, a bad thing? On one hand both methods are handy for different cases, but they do clutter the interface, making the interface more complex than it strictly have to be.
Would a design without a common interface be better? That would remove the fieldID, I don't why, but I think the fieldID-thing smells, I might be wrong. I would only make the Show and Hide methods, when needed, that is if they would be called by the controller. This would be a less generic solution and require more code in the view, but the controller code would be a bit more simple.
So a view interface might look like this:
public interface IMyView
{
void ShowName()
void HideName()
string Name { get; set; }
int Age { get; set; }
}