用户登录的UML类图

Ant*_*ony 18 oop uml design-patterns class-design

下图是我第一次尝试创建描述用户登录网站的UML类图.

rubbishlogindesign

我确信它的设计很差,并且有很多缺陷,但我希望向你们学习如何设计一个像这样的简单登录.我对您使用设计模式以及您将使用哪些模式,如何在设计中实现它以及原因感兴趣.

任何建议,批评,意见和建议将非常感激.提前致谢.

Art*_*ald 24

以下是我们如何实现这种功能


类图


如您所见,我们有很多应用程序(这里,它的行为与您的网站相似).

主持人,WebMaster和成员,如您的映射所示,它将更好地作为角色.无论您是否需要添加新的"角色",都会发生什么.也许你必须改变你的所有模型.

每个UserApplication(UserWebsite)都有其开始和结束日期.每个应用程序都有自己的角色.银行网站需要管理员角色.健康保险公司网站需要代理角色等等......

UPDATE

我理解登录/用户(部分/整体)组成关系.在继续之前,请参阅有关组合与聚合的答案.

但我不明白的是UserApplication和Application类的目的

将应用程序视为您的网站.我在一家大型健康保险公司工作,我们有很多模块(每个模块(应用程序)都有自己的网站).但是一些用户,不是所有用户,都可以使用每个模块.它解释了我定义UserApplication的原因.

角色在此登录过程中的角色

没有.它只是为UserApplication提供了一个角色.我可以使用财务模块,它定义了以下角色:经理,客户和其他,我可以在其中扮演经理的角色.但我可以为您分配一个临时用户(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);
Run Code Online (Sandbox Code Playgroud)

你的网站看起来像

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);
Run Code Online (Sandbox Code Playgroud)

如您所见,WebMaster,主持人和成员只是您网站定义的角色.没有其他的.

关于UML和ORM的一个很好的资源是Java Persistence with Hibernate一书.

  • 类图不再可见.不知道如何引起管理员的注意! (3认同)

ibr*_*maz 7

我检查了你的用例的描述.它是错的,它可以是:

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.”
Run Code Online (Sandbox Code Playgroud)

在编写完用例之后,就像这样绘制SSD.

替代文字http://i43.tinypic.com/2yozeb9.jpg

和这样的上述SSD的交互图.我假设你使用ORM(比如Hibernate,LinqToSql,EntityFramework ......所以在访问你的数据时你不需要外观模式.) alt text http://i40.tinypic.com/dg6vma .JPG

和伙计,你不要从一个用例中决定其他用户.所以拉尔曼说这个小组的用例并选择了一个小组来实施.此用例组在版本1中反映了您的类.因此,您无法获得许多类的一个用例.Just Read Larmans预订并查看这些演示文稿 http://faculty.inverhills.edu/dlevitt/CIS%202000%20Home%20Page.htm

如果你将责任分配给类实现将是如此简单.也许你不喜欢阅读,但有时我们应该读一些书.Larmans书是软件工程师最喜欢的书.任何一所大学都将本书用于面向对象的分析和设计.