[英]Question about UML class diagrams of library
Here is a simple question about my UML lesson's homework, and I'm not sure about what I've done.这是一个关于我的 UML 课程作业的简单问题,我不确定我做了什么。 Could you help me to get it corrected,I will be so grateful for yours kinds advices:你能帮我改正吗,我将非常感谢你的建议:
The exercise is to design a class structure for a library system.练习是为图书馆系统设计一个类结构。 It should fulfill those requirements:它应该满足这些要求:
Here is the UML diagram that I made:这是我制作的UML图:
At first sight, the diagram corresponds to the narrative, with some comments:乍一看,该图与叙述相对应,并附有一些评论:
Borrow
class could be called Borrowed
or History
; Borrow
类可以称为Borrowed
或History
; having two borrow
on the same diagram for different purpose is a source of confusion在同一张图上有两个用于不同目的的borrow
是混淆的根源borrow
shows that at a given moment a maximum of 4 books are borrowed.关联borrow
显示在给定时刻最多借出 4 本书。 But the minimum should be 0 ( no library user is obliged to always have a book).但最小值应该是 0(图书馆用户没有义务总是有一本书)。 Reciprocally not all books are borrowed at a moment in time: so it'd be 0..1反过来,并不是所有的书都是在某个时间借的:所以它是 0..1Now the diagram raises some question:现在这张图提出了一些问题:
I didn't follow your course, so I don't know what the teacher expects.我没有跟着你的课,所以我不知道老师的期望。 But here is how I'd modelled it:但这是我建模的方式:
borrow
association with an association class我使用了与关联类的多对多borrow
关联Another problem is included in the narrative: what is when an underage user becomes adult ?叙述中还包含另一个问题:未成年用户何时成为成年人? Your realization relation implies that two different users would exist for the same person (the new adult would loose the history).您的实现关系意味着同一个人将存在两个不同的用户(新成年人将丢失历史记录)。
For this reason, I'd suggest to use composition over inheritance : make user
a full class, compose with an Identification
, and make two concrete classes adultIdentification
, underageIdentificztion
.出于这个原因,我建议使用在继承组成:使user
一个完整的类,撰写与Identification
,并提出两个具体的类adultIdentification
, underageIdentificztion
。 So when an underaged user becomes adult, you keep user with history and change only the means of identification :-)因此,当未成年用户成为成年人时,您可以保留用户的历史记录并仅更改识别方式:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.