Given the classes Company
, Employee
, and Car
what is the preferred practice for methods to retrieve Cars associated with Company or Employee?
Employee.GetCars(params...)
Company.GetCars(params...)
Or:
Cars.GetByEmployee(params...)
Cars.GetByCompany(params...)
The first approach is the one I have generally used and always seemed the most intuitive to me. But after seeing a large code-base that used the second approach I have to admit that it's growing on me. The two things I really like about the second approach are:
- It groups all
Car
related code together into one file, making the code more modular and easier to maintain. - There is an intuitive logic to having any method with a return value of
Car
(or more likeList<Car>
in this case) grouped into theCar
class.
Is there a best practice that covers this?