具有聚合和泛化的类图
我正在做一个大学项目,我有以下我无法解决的问题。
我有一个名为 Employee 的课程 由此我概括了两类承包商雇员和永久雇员。
现在我有一个由两种类型的员工组成的团队,所以我计划使用聚合。
我是否必须将团队类连接到两个子类或员工类?
谢谢
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 generalize 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
到员工班。团队类将有一个员工列表;它不会关心他们实际上是 ContractorEmployees、PermanentEmployees 或 FooEmployees。
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.
嗯,有趣的问题...如果您的 Team 类仅指 Employee,那么您将来可以扩展到其他类型的员工(TeamLeads、Managers 等...)。如果您将 Team 类绑定到 Contractor 和 PermanentEmployee,那么您实际上是在说一个 Team 可以有 Contractors、Perm.Employees,并且没有其他内容!但也许这就是您想要的...
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
不要在团队和员工或其子类型之间使用聚合。 Team 类有一个属性“Members”,它是员工的集合。这样,团队可以拥有员工子类型的任意组合,包括以后添加的任何其他子类型。
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.