简体   繁体   English

UML +类图-在线电影租赁

[英]UML + Class Diagram - Online Movie rental

Create an object-oriented design for a streaming movie rental system (like NetFlix). 为流电影租赁系统(如NetFlix)创建一个面向对象的设计。 The names of your classes, private instance variables, methods etc. are totally up to you. 类的名称,私有实例变量,方法等完全取决于您。

Specifcation 规格

Every user has the following information associated with them: 每个用户都具有与之相关的以下信息:

  1. A name. 一个名字。
  2. An account number. 一个帐号。
  3. An ordered playlist of movies. 电影的有序播放列表。
    • In particular, if movie A is before movie B in the playlist, then the user watches A before B. 特别地,如果电影A在播放列表中在电影B之前,则用户在电影B之前观看A。
  4. The five most recent movies that the user has watched. 用户观看过的五部最近的电影。

There are three different kinds of users: 有三种不同的用户:

  1. Trial 试用版
    • A trial user can only have one movie in their playlist at a time. 试用用户一次只能在其播放列表中放映一部电影。
  2. Members 会员
    • A member can have up to 5 movies in their playlist at a time. 一个成员一次最多可以在其播放列表中包含5部电影。
  3. VIP Members VIP会员
    • A VIP member can have an unlimited number of movies in their playlist. VIP成员的播放列表中可以包含无限数量的电影。

Every user must be able to do the following operations: 每个用户都必须能够执行以下操作:

  1. Check-out a movie 签出电影
    • If a user checks out a movie, then it is put at the end of the user's playlist. 如果用户签出电影,则会将其放在用户播放列表的末尾。
  2. Watch a movie 看电影
    • If a user watches a movie, then the movie is removed from the user's playlist. 如果用户观看电影,则该电影将从用户的播放列表中删除。 You may assume that the user can only watch whatever movie is at the front of the playlist. 您可以假设用户只能观看播放列表前面的任何电影。
  3. Recall the five most recent movies that they have watched 回顾他们看过的五部最近的电影
    • This operation should print the most recent movies that the user has watched to the screen. 此操作应将用户观看的最新电影打印到屏幕上。

Every movie contains the following information: 每部电影都包含以下信息:

  1. A title 一个标题
  2. A date 一个约会
  3. A genre 体裁
  4. A rental price 租金价格

Notice that different users have different movie rental rights, so it is possible that a user will attempt to do something that (s)he is not allowed to do. 请注意,不同的用户具有不同的电影租赁权,因此用户可能会尝试执行不允许其做的事情。 When this occurs, you must do the following: 发生这种情况时,您必须执行以下操作:

  1. Make sure that the operation is not performed. 确保未执行该操作。
  2. Print an informative error message that states why the operation could not be performed. 打印一条信息性错误消息,指出为什么无法执行该操作。

Your object-oriented design must include the following object-oriented features: 您的面向对象的设计必须包含以下面向对象的功能:

  1. An abstract class 抽象类
    • What should be the base class that other classes build of? 其他类构建的基类应该是什么?
  2. Inheritance 遗产
    • In particular, you must inherit from a base abstract class. 特别是,您必须从基本抽象类继承。
  3. Polymorphism (Dynamic Binding) 多态性(动态绑定)
    • In particular, your method for checking a movie out must be polymorphic. 特别是,您检出影片的方法必须是多态的。

I have come up with the following class diagram, which is not yet completed: 我已经提出了以下尚未完成的类图:

在此处输入图片说明

to start with I am little confused about where the three functionalities should go... check out the movie, watch a movie and get the last 5 recent watched movies. 首先,我对这三个功能应该去哪里不太困惑...查看电影,观看电影并获取最近观看的5部电影。 Also, Would like to know how to relate these classes. 另外,想知道如何关联这些类。

I have edited my class diagram.. I am looking for some feedback on relationship of the classes 我已经编辑了班级图。.我正在寻找有关班级关系的一些反馈

在此处输入图片说明

I'll give you a bit of direction on the abstract class part of this. 我将为您提供有关抽象类部分的一些指导。 You have correctly understood that User is an abstract class, and that your concrete classes inherit from it. 您已经正确地了解到User是一个抽象类,而您的具体类则继承自它。 However, you do not need to have an attribute that explains what type of user a given instance is. 但是,您不需要具有解释给定实例是哪种类型的用户的属性。 Call your concrete classes NormalUser, TrialUser, VIPUser. 调用您的具体类NormalUser,TrialUser,VIPUser。 Make checkOut an abstract operation in your User class; 在您的User类中将checkOut进行抽象操作; since each concrete class handles this operation differently, you'll need to implement it in each class rather than in the User class. 由于每个具体类对此操作的处理方式都不相同,因此您需要在每个类中而不是在User类中实现它。 (The User class will directly implement those operations that each class does in the same way, such as getHistory.) User类将直接实现每个类以相同方式执行的那些操作,例如getHistory。)

The polymorphism bit is that you declare a class of type User and instantiate it as one of the concrete subclasses. 多态位是您声明用户类型的类并将其实例化为具体的子类之一。 Then, when you call the checkOut method, you will get the varying behavior you've implemented in the subclasses. 然后,当您调用checkOut方法时,您将获得在子类中实现的各种行为。

I'll also give you some syntax correction: 我还将给您一些语法更正:

Don't write "Concrete Class" in your concrete class labels, and don't put an «Abstract Class» stereotype in your abstract class label. 不要在具体类标签中写“具体类”,也不要在抽象类标签中放置“抽象类”构造型。 The way that UML shows a class to be abstract is to italicize the title. UML将类显示为抽象的方式是将标题倾斜。 That's all the distinction you need. 这就是您所需要的所有区别。

Don't put a «Class» stereotype on your classes. 不要在班级上放置“班级”刻板印象。 Stereotypes are to define a particular type of class such as «Utility». 刻板印象将定义类的特定类型,例如“实用程序”。

Don't write «Stereotype» on your class labels for the same reason. 出于同样的原因,不要在班级标签上写《刻板印象》。 There's no such stereotype already defined, and as Thomas Kilian says, a "stereotype" stereotype makes absolutely no sense so there's no reason to create one yourself. 还没有定义这种刻板印象,正如托马斯·基利安(Thomas Kilian)所说,“刻板印象”刻板印象绝对没有意义,因此没有理由自己创建一个刻板印象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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