1..n Relationships in Class Diagrams

Dear All,

I am a bit confused about class diagrams and ER diagrams in databases. I know how they are different, but I am stuck in one aspect. In an ER diagram if you have a 1…n relationship (say a department has many employees) then the primary key of department goes into the employee entity.

In a class diagram, should I do the same? Or should I have an operation under department entitled getemployees(D:Department) as otherwise information of the department class would go into employee, violating the encapsulation rule?

I look forward to hearing from you soon.

Thanks in advance.

George

Hi George

I think you’d draw an association between your dept and employee class, with a multiplicity of 1…* at the employee role end, and assuming that an employee is only in one dept, 1 at the dept role.

As for casting to code, some sorta collection.

:wink: Hope it helps.