Interface first development and Mocking [Overview]
January 9, 2011 Leave a comment
30 Second Overview
Although this technique really falls within the ‘Emergent Design Umbrella’ it would be remiss of me to not to write a quick overview.
This technique introduces two visualizing concepts to the reader:
- Coding shallow and wide
- Implementing deep
Ok so what does all that mean , well in simple terms your aim is to code in multiple passes the first pass you implement the behaviour to satisfy your BDD test by hammering out interfaces and you mock everything do not even allow your mind to wonder to the how do i implement X instead just trust that it will become clear as you proceed.
So in the first pass everything or almost everything is a mock and you will be passing values into one mock and pulling them out of another when you stand back and look at that first pass your first reaction will be that’s pointless, mine certainly was the first time i did.
But if you have now coded shallow.
So next start pushing down towards your deep end point perhaps a mocked repository or some such. So next you might make the Adapter concrete and start to implement a service call perhaps via a channel factory. This will of course lead you to implement the service and because we are best practise team you will be injecting into it via its constructor (DI/IOC) its repository which is still mocked.
So you will be driven in the setup code for your test to hammer out the host and perhaps a Unity (or other DI) service behaviour/host/ binding then you will rerun your test ad you will find that now you have coded deep and implemented the behaviour you prototyped in the first pass. So you move on till you get to the your test end point which might be a in memory database or a mocked repository or something else that suits your domain pattern.
The golden rule with this is ‘ Implement only when driven there, delay implementation of an object as long as practical and sensible’.