Part of the keyboard clique

Entries categorized as ‘Test Driven Development (TDD)’

Test driven development and type safety

December 20, 2005 · Leave a Comment

This post will not go into how tests are written. There are many excellent guides to test driven development on the net. I might post some links for this later. On to business…

Code won’t compile unless our objects talk to eachother as the compiler expects.

Take the example of the ATM from my last post. The ATM object has two responsibilities: login, getBalance. The compiler can ensure that a user object only invokes getBalance and login. That is called type safety. If we try to invoke some responsibility of the ATM object such as showStatement, which it does not have in the example, the compiler will scream and wail like a spoiled child. You will be forced to remove the offending line of code. What can go wrong now?

(more…)

Categories: Programming · Test Driven Development (TDD) · object oriented programming