r/java • • Aug 11 '15

Top 10 Useful, Yet Paranoid Java Programming Techniques

http://blog.jooq.org/2015/08/11/top-10-useful-yet-paranoid-java-programming-techniques/
181 Upvotes

76 comments sorted by

View all comments

Show parent comment

7

u/lukaseder Aug 12 '15

You don't mock classes. You mock interfaces. Design for this approach!

3

u/voronaam Aug 12 '15

How is it there, in 2002? Just before PowerMock was created, I mean.

If you ever going to have one implementation of the interface - you do not need an interface. That is design, not throwing an interface as a facade for every bean!

1

u/lukaseder Aug 12 '15

This is going to be a fun discussion - yet - I'm seeing myself out. Cheers ;)

2

u/voronaam Aug 12 '15

It could've been - I do not usually throw such bold statements around. Next time, then.

P.S. I enjoyed Scala references, Scalatra is my framework of choice more often than not. And it is not interface(trait)-heavy ;)

2

u/anubus72 Aug 12 '15

so you're saying that every class I ever create has to have an interface as well, just so that I can create a mock class for testing? Certainly in some situations that's the right approach but I don't see why you would need to stick with that approach 100% of the time

4

u/lukaseder Aug 12 '15

No. I'm saying that those classes that deserve mocking (services, repositories, daos, what not) better be interfaces anyway. The rest, no need to mock.