I'm building an application that manages holidays and absences from work using MVC patterns.
model
- Data layer - the properties of an absence
- Domain layer - load all the absences for an employee for a period
- Service layer - interacts with the domain layer and manipulate absence entities
I need to calculate the amount of holiday time used and available. Logically I'd do this in the service layer, that is get all the absences from the domain and iterate through them to get a result.
In the view I need to display all the absences and holidays used. This implies the system is loading the absences twice, once to calculate holiday usage and once to get a list to display.
Is this aright? In a non MVC but OOP world I would have an AbsenceList
class with a getHolidayUse()
method so the class would only need to be loaded from the database once.
Should I just accept that I'll need to load and destroy entities a lot and implement caching to cope with it?
Should I implement an AbsenceList
entity that includes the list of absences and has a holidayUsed
property that is calculated in the domain layer findAll()
method?