开发者

Interfaces and Coupling

开发者 https://www.devze.com 2022-12-16 10:08 出处:网络
From a design and loose coupling standpoint.Is it a good idea to have an interface for each class in a project that might be part of a composition model?

From a design and loose coupling standpoint. Is it a good idea to have an interface for each class in a project that might be part of a composition model?

I have a project where I'm doing this, but now I'm getting rather a lot of interfaces, in an attempt to开发者_运维知识库 keep things relatively loosely coupled.


Without knowing specifics of your design, that's how the Interface Segregation Principle (pdf) is supposed to work.

You should provide an interface for every class that you may need to swap out the implementation for (I wouldn't create an interface for each DTO, for example).


I generally create interfaces to loosely couple classes for testing so that I can create fakes for the classes I'm not interested in testing. EG a business logic manager class will have a reference to an interface for a data access class.

I only create an interface if I actually need a 'seam' for my tests, I don't just create interfaces for everything.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号