Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Service layer and DAO layer (interface+implementation) or implementation only

I am confused about the structure of creating service layer and DAO layer: in some examples I see some people creating interface+implementation for both service and DAO and in other examples I see people creating implementation only specially when the DAOs extends an AbstractDao class that contains generic methods for those DAOs, so I am confused about what to go for, why to go for this solution or the other one, and what is the best practise (commonly used) please advise.

like image 922
fresh_dev Avatar asked Nov 14 '11 12:11

fresh_dev


1 Answers

I suggest to create interfaces for service and for DAO. Very often you would like to mock service in unit tests of code, that use this serice. Also Spring, for example, forces you to use interfaces when you are using some Spring proxies for example for transactions. So you should have an interface for service.

DAO is more internal part, but I always try to use interfaces for them to simplify testing.

like image 82
dbf Avatar answered Sep 19 '22 18:09

dbf