3 ms·
Nothing crazy required public EmployeeController(EmployeeMapper mapper){} public Employee create() { ... mapper.save(employee); return employee; } Done. All
by npinguy 12y ago
Nothing crazy required
public EmployeeController(EmployeeMapper mapper){}
public Employee create() {
...
mapper.save(employee);
return employee;
}
Done.
All you do now is create a mock employee mapper in your tests, and you can verify just what you want in the Controller instead of anything else
You've got
* Single responsibility classes (Controller manages employee creation business logic; Mapper is a dumb database wrapper; If you want to go even further, use a Repository instead of a Mapper to introduce one more layer of abstraction between the data model, that way you can slide in caching or in-memory replacements, or what have you at will)
* Clean dependencies. There's nothing hidden about what this class needs to get it's work done
- crazytony 12y agoSo the "damaged" class is not really damaged. It's what you'll wind up with if you started with a small rails project and you had to scale it as it got popular? hmmm.