Hi everyone,
i'm new to object-oriented programming and i have a question.
Let's consider this example : two classes Employee and Project related by an association class Role which depict the role each employee has in projects.
Now suppose that i want to get a list with projects, employes and their roles.
I think i have to provide Project class with a method that retrieve from DB the list of all project and for each one the data about the employes and their role.
The question(s) is (are):
- should i create an instance of employee and role for each project i retrieve from the DB (suppose that i want to invoke some method of Role and get other data to show)
- If i want the detail about a specific employee should i load data from db (also about role and project) within the employee class and then create an instance of the related class? or each class should load data by itself?
I don't know which is the best way to implement this situation. does anyone have some advice?
thanks.
i'm new to object-oriented programming and i have a question.
Let's consider this example : two classes Employee and Project related by an association class Role which depict the role each employee has in projects.
Now suppose that i want to get a list with projects, employes and their roles.
I think i have to provide Project class with a method that retrieve from DB the list of all project and for each one the data about the employes and their role.
The question(s) is (are):
- should i create an instance of employee and role for each project i retrieve from the DB (suppose that i want to invoke some method of Role and get other data to show)
- If i want the detail about a specific employee should i load data from db (also about role and project) within the employee class and then create an instance of the related class? or each class should load data by itself?
I don't know which is the best way to implement this situation. does anyone have some advice?
thanks.