Upon reviewing a bunch of MVC style web applications, I'm noticing that it's common to have a very large service interface sitting in front of the business layer. The implementation of this interface usually includes a bunch of DAOs. So you have something like:
public class FoodServiceImpl implements FoodService {
private FruitDAO fruitDAO;
private VegetableDAO vegetableDAO;
private MeatDAO meatDAO;
// ... DAO injection stuff
public List<Meat> getMeat() {
return meatDAO.getMeat();
}
public void addMeat(Meat meat) {
meatDAO.add(meat);
}
public List<Fruit> getFruit() {
return fruitDAO.getFruit();
}
// ... tons of methods that mostly just delegate to DAOs
}
Assuming that your DAOs aren't concrete in the first place, why not just expose the DAOs to the next level up?
So instead of:
// assume foodService is injected at runtime
public void controllerMethod() {
foodService.getFruit();
foodService.getMeat();
}
You just have
// assume DAOs are injected at runtime
public void controllerMethod() {
fruitDAO.getFruit();
meatDAO.getMeat();
}
On one hand it looks kinda nice to have the entire guts of the application wrapped up in a single interface.... on the other hand you can end up with a giant interface whose implementation does nothing much more than delegating to DAOs.
I can see that it's nice to manage all of the DAOs in one place. I can also imagine that this pattern would be useful if the same DAOs were going to be used via multiple services.
Is this considered a "best practice" when starting a web application, or does it only apply when a certain level and type of complexity is expected?