简体   繁体   English

用户登录的UML类图

[英]UML Class Diagram for User Login

The diagram below is my very first attempt at creating a UML class diagram describing a user login into a website. 下图是我第一次尝试创建描述用户登录网站的UML类图。

rubbishlogindesign

I'm sure its a poor design and full of flaws, but I'm hoping to learn from you guys how you would design a simple login like this. 我确信它的设计很差,并且有很多缺陷,但是我希望向你们学习如何设计一个像这样的简单登录。 I'm particularly interested in your use of design patterns and which patterns you would use, how you would implement it in the design, and why. 我对您使用设计模式以及您将使用哪些模式,如何在设计中实现它以及原因感兴趣。

Any advise, criticisms, comments and suggestions will be really appreciated. 任何建议,批评,意见和建议将非常感激。 Thanks in advance. 提前致谢。

Here is how we implement this funcionallity 以下是我们如何实现这种功能


类图


As you can see, we have many Application (Here, it behaves like your website). 正如您所看到的,我们有很多应用程序(这里,它的行为与您的网站相似)。

Moderator, WebMaster and Member, as shown in your mapping, it would be better as a Role. 主持人,WebMaster和成员,如您的映射所示,它将更好地作为角色。 What happens whether you need to add a new "Role". 无论您是否需要添加新的“角色”,都会发生什么。 Maybe you have to change all of your model. 也许你必须改变你的所有模型。

Each UserApplication (UserWebsite) has its start and end date. 每个UserApplication(UserWebsite)都有其开始和结束日期。 And each Application has its own Role. 每个应用程序都有自己的角色。 A Bank website needs a Manager role. 银行网站需要管理员角色。 A Health Insurance Company website needs a Agent role and so on... 健康保险公司网站需要代理角色等等......

UPDATE UPDATE

I understand the login/user (part/whole) composition relationship. 我理解登录/用户(部分/整体)组成关系。 Before going on, see this answer about Composition versus Aggregation. 在继续之前,请参阅有关组合与聚合的答案

But what I do not understand is the purpose of the UserApplication and Application classes 但我不明白的是UserApplication和Application类的目的

Think of Application as your website. 将应用程序视为您的网站。 I work for a big Health Insurance Company where we have many modules (Each module (Application) has its own website). 我在一家大型健康保险公司工作,我们有很多模块(每个模块(应用程序)都有自己的网站)。 But some Users , not all, can use each module. 但是一些用户 ,不是所有用户 ,都可以使用每个模块。 It explains why i define UserApplication. 它解释了我定义UserApplication的原因。

role's role in this login process 角色在此登录过程中的角色

None. 没有。 It just gives an UserApplication a role. 它只是为UserApplication提供了一个角色。 I can use the financial module, which defines the following roles: Manager, Customer and Other, where i can play the role of Manager. 我可以使用财务模块,它定义了以下角色:经理,客户和其他,我可以在其中扮演经理的角色。 But i can assign you a Temporary User (startDate and endDate) as Customer to use the financial module. 但我可以为您分配一个临时用户(startDate和endDate)作为客户使用财务模块。

Application financialModule = new Application();

financialModule.addRole(new Role("Manager"));
financialModule.addRole(new Role("Customer"));
financialModule.addRole(new Role("Other"));

User arthur = new User(new Login("#####", "#####"));
arthur.setFirstName("Arthur");
arthur.setLastName("Ronald");
arthur.setEnabled(true);

UserApplication financialModuleUser = new UserApplication(new Period(new Date(), null));
financialModuleUser.setUser(arthur);
financialModuleUser.addRole(financialModule.getRoleByDescription("Manager"));

financialModule.addUserApplication(financialModuleUser);

Your website looks like 你的网站看起来像

Website myWebsite = new Website();
myWebsite.addRole(new Role("Member"));
myWebsite.addRole(new Role("WebMaster"));
myWebsite.addRole(new Role("Moderator"));

User you = new User(new Login("#####", "#####"));
you.setFirstName("FirstName");
you.setLastName("LastName");
you.setEnabled(true);

UserApplication myWebsiteUser = new UserApplication(new Period(new Date(), null));
myWebsiteUser.setUser(you);
myWebsiteUser.addRole(myWebsite.getRoleByDescription("WebMaster"));

myWebsite.addUserApplication(myWebsiteUser);

As you can see, WebMaster, Moderator and Member are just roles defined by your website. 如您所见,WebMaster,主持人和成员只是您网站定义的角色 Nothing else. 没有其他的。

A good resource about UML and ORM is Java Persistence with Hibernate book. 关于UML和ORM的一个很好的资源是Java Persistence with Hibernate一书。

i examined the description of your use case.,it is wrong,it can be : 我检查了你的用例的描述。它是错的,它可以是:

Use Case: Login The System
Scope: Your Project Name.
Primary Actor: User
StakeHolders and Interests:
User: want to sign-in the system without any mistake or error.
Preconditions: User should be the system user
Success Guarantee: User entered the system
Main Success Scenario:
1.  User enters login page.
2.  System builds login page. Fields such as username and password  are observed on the screen.
3.  Users enters required informations.
4.  Users sends information with a view to entering the system.
5.  System approves information, open the session of user and returns message ”Login process is successfull”.
Alternate flows:
      3a.User does not enter all required field.
              1.System wait that user enter so-called required field.
       4a.The information of user such as username or password is wrong
              1.System send message ”Your send wrong user parameters.”

After you write the your use case,you draw your SSD like this. 在编写完用例之后,就像这样绘制SSD。

替代文字

and interaction diagram of aforementioned SSD like this.I assumed you use the ORM(like Hibernate,LinqToSql,EntityFramework... so you dont need facade pattern when accesing your Data.) 像这样的上述SSD的交互图。我假设您使用ORM(如Hibernate,LinqToSql,EntityFramework ......所以在访问数据时不需要外观模式。) 替代文字

and dude , you dont decide other users from one usecase. 和伙计,你不要从一个用例中决定其他用户。 So Larman says that group ur use case and chose one group for implementation. 所以拉尔曼说这个小组的用例并选择了一个小组来实施。 This use case group reflect your class in version 1. so one use case you cant obtain many class. 此用例组在版本1中反映了您的类。因此,您无法获得许多类的一个用例。 Just Read Larmans book and look these presentation http://faculty.inverhills.edu/dlevitt/CIS%202000%20Home%20Page.htm Just Read Larmans预订并查看这些演示文稿http://faculty.inverhills.edu/dlevitt/CIS%202000%20Home%20Page.htm

if you assign responsibility to the classes implementation will be so easy. 如果你将责任分配给类实现将是如此简单。 maybe you dont like reading but sometimes we should read some books.Larmans book is one favourite book of Sofware Engineers. 也许你不喜欢阅读,但有时我们应该读一些书.Larmans书是软件工程师最喜欢的书。 Any many university use this book their Object Oriented Analysing and Design. 任何一所大学都将本书用于面向对象的分析和设计。

i adviced you to use Grasp Design pattern for making good design.According to this discipline ,firsty you should think who responsible for making this operation.Which class is responsible or which method. 我建议你使用Grasp Design模式进行优秀的设计。根据这个规则,你应该想到谁负责这个操作。哪个班负责或哪个方法。 To sum up you will also see that Gof pattern's root is Grasp. 总结一下,你也会看到Gof模式的根是Grasp。 in your design,im sorry i regret to say your use case is not well defined and this class diagram should be your domain model because it reflects concepts in your usecase. 在你的设计中,对不起,我很遗憾地说你的用例没有很好的定义,这个类图应该是你的域模型,因为它反映了你的用例中的概念。 I m opposed to make class diagram prior to making system sequence and interaction diagram about the so-called usecase. 我反对在制作关于所谓的用例的系统序列和交互图之前制作类图。 in your domain model Regular member, web master and moderator is a user and we can say use user account . 在您的域模型中,常规成员,Web主管和主持人是用户 ,我们可以说使用用户帐户 by the way dont make inheritance as long as you should not,because it increase coupling of your class , so u cant make readly refactoring. 顺便说一下,只要不这样做就不要继承,因为它会增加你的类的耦合,所以你不能重新进行重构。 http://en.wikipedia.org/wiki/GRASP_(Object_Oriented_Design) http://en.wikipedia.org/wiki/GRASP_(Object_Oriented_Design)

替代文字

http://www.amazon.com/Applying-UML-Patterns-Introduction-Object-Oriented/dp/0130925691 http://www.amazon.com/Applying-UML-Patterns-Introduction-Object-Oriented/dp/0130925691

I see 2 places I would change: 我看到我会改变的两个地方:

1) Database is not a class and should not be shown in a class diagramm. 1)数据库不是一个类,不应该在类中显示。 This is probably actual for User_account (as I understand it's a table inside DB) 对于User_account来说这可能是实际的(据我所知,它是DB中的一个表)

2) When 3 classes are inherited from 1 superclass (WebMaster, Moderator, RegularMember from User) it's also shown as I drew below: 2)当从1个超类(WebMaster,Moderator,来自User的RegularMember)继承3个类时,它也显示如下:

                 1     uses>   1..*
          User <>--------------->UserAccount
           /|\
            |
            |
     _______|________
     |      |       |
     |      |       |
   Mod     WebM   RegularM

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

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