问题描述
我有4张桌子:
医生
ID,姓名,房间号
DoctorsID,Name,roomNumber
约会
ID,如果发生,如果参加
AppointmentsID,whenOccured,ifAttended
患者
ID,姓名,地址
PatientsID, name, address
DP约会
DoctorID,PatientID,AppointmentID
DPappointmentsDoctorID,PatientID,AppointmentID
这大致变成
但是,我现在要更改它以便可以进行约会
However, i now want to change it such that an appointment can be made to see either a Doctor OR a NURSE?
如何更改类图以反映 OR类型的关系?
How can i change the class diagram to reflect an 'OR' type relation?
推荐答案
根据模型的其余结构,有不同的解决方案。我认为这里还有一个Nurse类,并且id与Doctor没有任何特殊关系(例如从Employee继承或类似的继承)。因此,这将是一个通用的解决方案。
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.
添加在约会和护士之间添加关联,类似于现有的带有医生的关联。 Doctor(和Nurse)端的对应多重度应为0..1,并应添加一条附加规则-约会对象必须具有Doctor对象或Nurse对象的链接。
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.
此规则可以在OCL中指定(如果您喜欢正式样式),也可以在图表上作为简单的文字注释来指定。
This rule could be specified in OCL (if you like a formal style) or as a simple textual note on the diagram.
还有其他一些方法可以对此建模,没有其他限制,但是模型本身(可能)很复杂。例如,您可以从抽象类 AppointmentRespondent 派生Doctor and Nurse,并使用那一侧的多重性1..1将其与约会相关联。此模型具有更大的灵活性,并且更易于扩展(易于添加新的潜在的AppointmentRespondents),无OCL,无限制。
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.
PS并不是说这不是一种OR关系,而是XOR-在每次约会中都必须有人代表医院(这是一个合理的猜测:))。
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 :)).
这篇关于UML类图-“ OR”的表示法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!