UML Class Diagram for User Login

80,422

Solution 1

Here is how we implement this funcionallity


Class Diagram


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. 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. 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

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

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.

role's role in this login process

None. It just gives an UserApplication a role. 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.

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. Nothing else.

A good resource about UML and ORM is Java Persistence with Hibernate book.

Solution 2

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.

alt text

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.) alt text

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. Just Read Larmans book and look these presentation 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. Any many university use this book their Object Oriented Analysing and Design.

Solution 3

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. To sum up you will also see that Gof pattern's root is Grasp. in your design,i m 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. 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)

alt text

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

Solution 4

I see 2 places I would change:

1) Database is not a class and should not be shown in a class diagramm. This is probably actual for User_account (as I understand it's a table inside DB)

2) When 3 classes are inherited from 1 superclass (WebMaster, Moderator, RegularMember from User) it's also shown as I drew below:

                 1     uses>   1..*
          User <>--------------->UserAccount
           /|\
            |
            |
     _______|________
     |      |       |
     |      |       |
   Mod     WebM   RegularM
Share:
80,422
Anthony
Author by

Anthony

Do you love the Great Books of the Western Civilization? Let's start a reading group! I'm currently studying: What Every Computer Science Major Should Know Programmer's Competency Matrix Coursera edX Must reads: Don't Call Yourself a Programmer Must listens: Software Engineering Radio

Updated on July 09, 2022

Comments

  • Anthony
    Anthony almost 2 years

    The diagram below is my very first attempt at creating a UML class diagram describing a user login into a website.

    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.

  • Anthony
    Anthony over 14 years
    Thanks for your reply Roman. Yeah I knew I should not have named that class that talks to the database "Database". I should have been clearer with that. So how would you validate the login credentials of the user? I was going to store these credentials in the database and just have a class communicate with the database and validate the login with what's stored in the database.
  • Anthony
    Anthony over 14 years
    @Roman, yes I see it now, User (abstract class maybe) has an aggregation relationship with UserAccount, and the super classes (Mod, WebM and RegularM) all inherit this relationship from User.
  • Anthony
    Anthony over 14 years
    +1, thank you Arthur, for taking the time to show me how you actually implement a login, I really appreciate this. It very helpful. Ok, so I understand the login/user (part/whole) composition relationship. But what I don't understand is the purpose of the UserApplication and Application classes. I see that every user uses a UserApplication, and one Application can, I suppose, generate 1 or more UserApplications, but can you give me an example of what a UserApplication can be. Also, the Role's role in this login process, Im not quite sure what role this class plays with relation to the user.
  • Anthony
    Anthony over 14 years
    +1, thank you for recommending this book and GOF's book. You don't have to be sorry, I know my design is faulty lol. Your right, I did base my class diagram solely on the USE case diagram. Thanks for suggesting my three users should be "user" and about the problems of coupling, I need to research this. Thanks.
  • Anthony
    Anthony over 14 years
    @egebilmuh, can you recommend any forums that focus on designing code using UML?
  • Anthony
    Anthony over 14 years
    @Arthur, can you recommend any forums that focus on designing code using UML?
  • Anthony
    Anthony over 14 years
    @Arthur Garcia, thank you once again for taking the time to explain this to me. The Java code really helped.
  • Anthony
    Anthony over 14 years
    @egebilmuh, thank you very much. I really appreciate your frankness, and you were to the point. You taught me an alternative way in which I will do some more reading on. Thanks again
  • Anthony
    Anthony over 14 years
    @Arthur, I accidently +1 rated you which had the effect of removing my previous up vote and I could not put it back because the post is too old. I think you deserve +1 but this limitation sucks
  • Anthony
    Anthony over 14 years
    @Arthur, your most welcome but sorry about the accidental removal of the +1, now I can't put it back. Thanks again.
  • Dzung Nguyen
    Dzung Nguyen over 13 years
    wow, I really to thank this great answer. I have to implement the same function in my project this semester :)
  • Srik
    Srik about 10 years
    The class diagram is no longer visible. Not sure how to get the attention of admins!
  • Яois
    Яois almost 10 years
    @ArthurRonald could you upload the image again? Please, I'd like to see this design :)
  • Ivan
    Ivan almost 8 years
    I ended up, because I'm refactoring our login process, however - not sure if any picture i s missing here, but - where are the methods of your classes ?
  • Maihan Nijat
    Maihan Nijat almost 7 years
    @ArthurRonald What is an advantage of separating Login class from User class?