I am really interested what the root for this antipattern is. I have the suspicion that once people misunderstood "program to interfaces not implementations" and took it literally.
When seeing this pattern I tell programmers that every time they do this a little puppy drowns 😬
I'm curious, do you use dependency injection and unit test heavily?
I've gotten into the pattern of creating interfaces for almost all of my classes so that except for the code that needs to construct the object everything can refer to the interface. This makes mocking out that dependency WAY easier with better test performance to boot.
Agree with this. It's not just about communicating with external systems but testing would be a lot easier if dependencies are passed in and we don't create new instances that depend on other classes
Well, for me, a unit isn’t always equal to a class. In other words: I test several classes together. I know people have strong opinions about isolation- for me, it works just fine, and there are several TDD practioners who advocate this style (among them Martin Fowler and Kent Beck, if I‘m not mistaken).
That's a fair approach. I'm certainly not dogmatic about this stuff; as long as you have a good understanding of the pros and cons involved and accept them, like you do here, that's fine. I do think this takes a bit more discipline around understanding what the "unit under test" is, so adoption could be an issue depending your team.
I don't recall reading anything by Fowler on this specific subject and I ❤️ that man. You wouldn't happen to know the book/blog/talk off hand would you? Sometimes searching for these things can prove to be difficult.
I found a pretty lengthy explanation of Robert Martin, a.k.a. Uncle Bob, who also prefers to test several classes at once if necessary: blog.cleancoder.com/uncle-bob/2017...
There’s more :) Here’s the interview of Martin Fowler, Kent Beck and DHH about DHHs article “TDD is dead” where they mention that they don’t mock that much. martinfowler.com/articles/is-tdd-d...
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I am really interested what the root for this antipattern is. I have the suspicion that once people misunderstood "program to interfaces not implementations" and took it literally.
When seeing this pattern I tell programmers that every time they do this a little puppy drowns 😬
I'm curious, do you use dependency injection and unit test heavily?
I've gotten into the pattern of creating interfaces for almost all of my classes so that except for the code that needs to construct the object everything can refer to the interface. This makes mocking out that dependency WAY easier with better test performance to boot.
Agree with this. It's not just about communicating with external systems but testing would be a lot easier if dependencies are passed in and we don't create new instances that depend on other classes
Well, for me, a unit isn’t always equal to a class. In other words: I test several classes together. I know people have strong opinions about isolation- for me, it works just fine, and there are several TDD practioners who advocate this style (among them Martin Fowler and Kent Beck, if I‘m not mistaken).
You get fewer tests, that don’t break easily when the implementation changes. The downside is errors are a bit more difficult to find.
That's a fair approach. I'm certainly not dogmatic about this stuff; as long as you have a good understanding of the pros and cons involved and accept them, like you do here, that's fine. I do think this takes a bit more discipline around understanding what the "unit under test" is, so adoption could be an issue depending your team.
I don't recall reading anything by Fowler on this specific subject and I ❤️ that man. You wouldn't happen to know the book/blog/talk off hand would you? Sometimes searching for these things can prove to be difficult.
I found a pretty lengthy explanation of Robert Martin, a.k.a. Uncle Bob, who also prefers to test several classes at once if necessary: blog.cleancoder.com/uncle-bob/2017...
Thanks for the Sunday reading!
There’s more :) Here’s the interview of Martin Fowler, Kent Beck and DHH about DHHs article “TDD is dead” where they mention that they don’t mock that much. martinfowler.com/articles/is-tdd-d...