UML Class Diagram - Notation for 'OR'

天大地大妈咪最大 提交于 2019-12-11 11:08:01

问题


I have 4 tables:

Doctors ID,Name,roomNumber

Appointments ID,whenOccured,ifAttended

Patients ID, name, address

DPappointments DoctorID,PatientID,AppointmentID

this roughly becomes

However, i now want to change it such that an appointment can be made to see either a Doctor OR a NURSE?

How can i change the class diagram to reflect an 'OR' type relation?


回答1:


Depending on the rest of your model's structure, there are different solutions. I supose there is also a class Nurse and that id does not have any special relationship with the Doctor (like inheritance from Employee or similar). So, this would be a generic solution.

Add add an association between Appointment and Nurse, similar to the existing one with a Doctor. The corresponding multiplicity on the Doctor (and Nurse) side should be 0..1 and an additional rule should be added - an Appointment object must have either a link to the Doctor object or to a Nurse object.

This rule could be specified in OCL (if you like a formal style) or as a simple textual note on the diagram.

There are some other ways to model this, with no additional restrictions, but the model itself would (maybe) be necessery complicated. For example, you could derive Doctor and Nurse from an abstract class - AppointmentRespondent and link it with the Appointment using the multiplicity 1..1 on that side. This model permits more flexibility and is more exdensible (easy adding new potential AppointmentRespondents), no OCL, no restrictions.

It's up to you to chose the method that is more in line with your model and future extensions.

P.S. Not that this is not an OR-type of relation, but rather XOR - in each Appointment there MUST be somewhone on behalf of the hospital (this is a reasonable guess :)).



来源:https://stackoverflow.com/questions/23593667/uml-class-diagram-notation-for-or

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!