Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you define an interface for every public class in your domain model? Pros and Cons? [closed]

Do you implement an interface for every public class in your domain model? Pros and Cons?

Update: If Repositories interfaces and domain model classes are defined in separate assemblies, wouldn't there be circular dependency if we do not define interfaces for every domain class.

like image 498
StackUnderflow Avatar asked Nov 29 '22 07:11

StackUnderflow


2 Answers

No.

Cons.

  1. Noise code.
  2. More to write.
  3. YAGNI.
like image 189
Mike Chaliy Avatar answered May 10 '23 23:05

Mike Chaliy


You should define interfaces for dependencies between layers, not for every class. So your Service layer should depend on a repository interface, and your presentation layer should depend on a service interface. Past that, there aren't many hard and fast rules, other then use them where it makes sense.

Common sense is a good part of any good design.

like image 24
Matt Briggs Avatar answered May 10 '23 23:05

Matt Briggs