views:

17

answers:

1

In my app i am now facing several issues of where to perform some calculations. I am using Repository Pattern... (at least trying to) Here's how it works.. each Employee has many Physical_Exams.. and for each employee I need to be able to get his Initial Body_Mass_Index and his Last Body_Max_Index... of course each exam has a Date attribute... so for each employee I should be able to get these values

So my question is.. should the appropiate method be called like this

    Employee employee=EmployeeRepository.GetbyId(id);
    float initial_mass_index=employee.GetInitialMassIndex();

or like this?

    Employee employee=EmployeeRepository.GetbyId(id);
    float initial_mass_index=EmployeeRepository.GetInitialMassIndex(employee);

I think it's worth mentioning that each Employee has a company so for each company I will also need to calculate the Average Initial Mass Index of its employees... The question is the same... should the method that calculates this Average be defined in the Company Partial class or in the CompanyRepository??

Please Help!

+2  A: 

Personally, I would remove the method all together and replace it with a Public Property on the Employee type:

float initialMassIndex = employee.InitialMassIndex;

The fact that it is a property makes this decision much more clear. It is a piece of information that belongs to an Employee rather than something that should be fetched from an Object Repository.

Justin Niessner
Wouldnt that mean changing my Database?? my Employee table doesnt have a field called InitialMassIndex.... employees have physical exams... and from those physical exams I get their initial mass index and their current mass index
NachoF
@NachoF - If this is an Entity Framework (or LINQ to SQL) generated class, you can add more code in separate files using Partial Classes. This allows you to add properties without changing the database. If the value is calculated on the fly, I would consider changing the property name to simply MassIndex.
Justin Niessner
I still don't understand how I would go about setting the value of this property without making calls to the database.. remember that the initialMassIndex and CurrentMassIndex are calculated based on the dates of the physical exams the employee has taken.. its LinqToSql btw
NachoF