I want to follow up a comment I made on
Roy Osherove's blog about how a
.NET interfaces, like Perl 6 roles, to me should be used when you need to share behavior between otherwise unrelated objects (a Pet Dog and a Pet Cat, for instance). Requiring a
Why should this be the case? The only explanations I can come up with are:
Ever since I discovered the power of mock objects (to the point of writing Test::MockDBI), I realized that mock objects are the logical next step after plain code stubs, as mock objects let you simulate the behavior of the outside world so you can easily test your code without building a 1.1 billion-row test database (for example). Almost any time your code needs to communicate with the outside world, you can test first with mock objects as a mock-up of the real world objects. For much testing (esp. automation-assisted testing like Test::More provides), you do not need the objects outside of the class you are testing to respond to arbitrary inputs you just need them to respond to the particular inputs your test code will end up generating. Mock objects are perfect for this use, as their behavior will match how the real objects behave (within the limits of how you program the mock objects, of course).
I can think of a couple of ways that might work around this current limitation, if the mocking-requires-interface decision was because system classes should not be overridden without the user's consent:
To sum up: Someway, somehow Microsoft's
Been There. Done That. (Score:1)
The later verison of TypeMock.NET do allow you to mock classed without interfaces. Last I checked, it still had a problem with mocking a superclass of a current class, or maybe that's a superclass that is in unmanaged code.
Either way, much harder than in Perl TDD...and I sure do miss local() sometimes too.
Re: (Score:1)