I am working on a university project and i have the following problem i can not figure out.
I have a class Called Employee from this i g开发者_C百科eneralize two classes Contractor employee and Permanent Employee.
Now i have a team that is made by both types of Employee so i am planning to use aggregation.
Do i have to connect the team class to the two subclasses or to the employee class?
Thanks
To the employee class. The team class will have a list of Employees; it won't care it they're actually ContractorEmployees, PermanentEmployees, or FooEmployees.
Hmm interesting question... If your Team class only refers to Employee, you'd be able to expand in the future to other types of Employees (TeamLeads, Managers, etc...). If you bind your Team class to Contractor and PermanentEmployee, you are effectively saying that a Team can have Contractors, Perm.Employees, and nothing else! But maybe that's what you want...
Take a look here: Composition Associations
In UML 2, aggregation would be shown with an open diamond.
Don't use aggregation between Team and Employees or their subtypes. The Team class has a attribute 'Members' which is a collection of Employees. This way the Team can have any combination of Employee subtypes including any other subtypes added later.
精彩评论