Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Dependency Injection + Mockito allows one to do that. There's a whole study on writing code that's easy tested. Our rule is no more than 4 layers: initiator, business logic, services, anemic domain model. Initiators abstract away the inbound protocol and serialize to the common model. Business logic controller handle all of the branching. Services effectuate single actions. Services can't call other services. And the domain model is how everything talks. We all build our apps this way and it's really easy to move people between projects. Not perfect but works for about 85% of stuff one has to write.


I'm not sure calling the domain layer "anemic" by default is correct, as it's typically a (negative) descriptions of models which are too data-driven instead of behavior-driven. I would suggest an alternative layer structure: Initiators/Controllers -> Application/Domain/Infrastructure Services -> Domain Models/Business Rules/Invariant Checking


We've thought about that; the style I've described is very non-OO. It is easy to teach though and it makes unit testing a breeze.

I like the architecture you've described. I think we arrived at where did because it's a natural for when using a DI container, which manages state and transaction groups for you.


is database access only in service?


Correct. A business logic controller can not directly corner the outside world, it must talk through a service.

This is nice because it prevents leaky abstractions into the controller layer. Actions across services that need to be atomic can be grouped in an XA transaction:

// Xa start databaseService.reset password(user); emailService.notifyPasswordChange(user); // Xa commit




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: