class relationships [modified]
-
I am trying to put this into actual class and i am having difficutlties in it. I am not sure how to show relationships. I have put down some classes that it may need. Build a class called Employee reporting relationships. The class will be used as a part of some application. Its main purpose is to keep and maintain data related to the reporting relationships between employees within an organization. Employee can have zero or more managers. Manager is an employee who has one or more other employees reporting to him. Class EmployeeReportingRelationships { } Class Employee { } Class Manager:Employee { }
modified on Wednesday, June 23, 2010 1:47 AM
-
I am trying to put this into actual class and i am having difficutlties in it. I am not sure how to show relationships. I have put down some classes that it may need. Build a class called Employee reporting relationships. The class will be used as a part of some application. Its main purpose is to keep and maintain data related to the reporting relationships between employees within an organization. Employee can have zero or more managers. Manager is an employee who has one or more other employees reporting to him. Class EmployeeReportingRelationships { } Class Employee { } Class Manager:Employee { }
modified on Wednesday, June 23, 2010 1:47 AM
-
I'm afraid noone will do your homework for you. Try thinking further, and come back with a more precise question.
-
I am trying to put this into actual class and i am having difficutlties in it. I am not sure how to show relationships. I have put down some classes that it may need. Build a class called Employee reporting relationships. The class will be used as a part of some application. Its main purpose is to keep and maintain data related to the reporting relationships between employees within an organization. Employee can have zero or more managers. Manager is an employee who has one or more other employees reporting to him. Class EmployeeReportingRelationships { } Class Employee { } Class Manager:Employee { }
modified on Wednesday, June 23, 2010 1:47 AM
So you need to break down the requirements into logical parts. Employee can have zero or more managers. So, your
Employee
class will need a property that has a variable size that is of typeManager
. Perhaps a List<Manager> Manager is an employee... So theManager
class should derive fromEmployee
as you have already done. ...who has one or more other employees reporting to him. So theManager
class needs an additional property that has a variable size that is of typeEmployee
. Possibly, the extra Manager class isn't needed as checking this property is > 0 will indicate that they are manager anyway. This is what programming is all about, turning real world situations into code and in the case of OOP creating objects to represent them and adding properties to give the details/descriptions of thos objects and methods/events for the things they actually do. Not really that hard to grasp.Dave
If this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
So you need to break down the requirements into logical parts. Employee can have zero or more managers. So, your
Employee
class will need a property that has a variable size that is of typeManager
. Perhaps a List<Manager> Manager is an employee... So theManager
class should derive fromEmployee
as you have already done. ...who has one or more other employees reporting to him. So theManager
class needs an additional property that has a variable size that is of typeEmployee
. Possibly, the extra Manager class isn't needed as checking this property is > 0 will indicate that they are manager anyway. This is what programming is all about, turning real world situations into code and in the case of OOP creating objects to represent them and adding properties to give the details/descriptions of thos objects and methods/events for the things they actually do. Not really that hard to grasp.Dave
If this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Thanks Dave, your comments were really helpful. I've given you my vote of 5. However there is still a little confusion about the relationship, how could i get a list of managers for a given employee. For example, let's say I have an employee named "Frank" and he has two managers (Sean and manager2).
-
Thanks Dave, your comments were really helpful. I've given you my vote of 5. However there is still a little confusion about the relationship, how could i get a list of managers for a given employee. For example, let's say I have an employee named "Frank" and he has two managers (Sean and manager2).
You should keep a list of the managers - something like this...
public class Employee
{
private string name;
private List<Manager> managers;public string Name { get { return name; } set { name = value; } } public List<Manager> Managers { get { if(managers == null) return new List<Manager>(); return managers; } set { managers = value; } }
}
Dave
If this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)modified on Thursday, June 24, 2010 6:04 AM
-
I am trying to put this into actual class and i am having difficutlties in it. I am not sure how to show relationships. I have put down some classes that it may need. Build a class called Employee reporting relationships. The class will be used as a part of some application. Its main purpose is to keep and maintain data related to the reporting relationships between employees within an organization. Employee can have zero or more managers. Manager is an employee who has one or more other employees reporting to him. Class EmployeeReportingRelationships { } Class Employee { } Class Manager:Employee { }
modified on Wednesday, June 23, 2010 1:47 AM