简体   繁体   English

关于库UML类图的问题

[英]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:它应该满足这些要求:

  1. There are two types of users - under-aged and adults.有两种类型的用户 - 未成年人和成年人。
  2. Under-aged users are identified with usage of their full name and student card.未成年用户使用其全名和学生卡进行识别。
  3. Adult users are identified with usage of their full name and ID card.成人用户通过使用他们的全名和身份证来识别。
  4. The library contains books.图书馆藏书。
  5. There is basic information about every book (title, author, etc).每本书都有基本信息(书名、作者等)。
  6. The user can borrow at most 4 books at the same time.用户最多可同时借阅 4 本书。
  7. There is a history of previously borrowed books for every user (along with all the dates)每个用户都有以前借书的历史记录(以及所有日期)

Here is the UML diagram that I made:这是我制作的UML图:

在此处输入图片说明

At first sight, the diagram corresponds to the narrative, with some comments:乍一看,该图与叙述相对应,并附有一些评论:

  • The Borrow class could be called Borrowed or History ; Borrow类可以称为BorrowedHistory having two borrow on the same diagram for different purpose is a source of confusion在同一张图上有两个用于不同目的的borrow是混淆的根源
  • This class would need all the dates: sonthe start of the borrowing and the return if the borrowing.这个班级需要所有的日期:借用的开始日期和借用的归还日期。
  • The association 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..1

Now the diagram raises some question:现在这张图提出了一些问题:

  • does a book that is currently borrowed already appear in the history with an empty return date ?当前借出的书是否已出现在历史记录中且归还日期为空?
  • if not, how do we keep track of the borrowing start date.如果没有,我们如何跟踪借款开始日期。

I didn't follow your course, so I don't know what the teacher expects.我没有跟着你的课,所以我不知道老师的期望。 But here is how I'd modelled it:但这是我建模的方式:

  • I'd used a many to many borrow association with an association class我使用了与关联类的多对多borrow关联
  • the history information would be in the association class历史信息将在关联类中
  • the limit of maximum four books borrowed would be expressed with a constraint.最多可借四本书的限制将用约束表示。

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 ,并提出两个具体的类adultIdentificationunderageIdentificztion 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM