Why is it so bad to mock classes?

前端 未结 9 1889
一向
一向 2020-12-07 17:57

I recently discussed with a colleague about mocking. He said that mocking classes is very bad and should not be done, only in few cases.

He says that only interfaces

9条回答
  •  隐瞒了意图╮
    2020-12-07 18:18

    IMHO, what your colleague means is that you should program to an interface, not an implementation. If you find yourself mocking classes too often, it's a sign you broke the previous principle when designing your architecture.

提交回复
热议问题