Search code examples
umldaovisioclass-diagramdomain-model

In UML class diagram, where to show DAO methods of a domain class


I am trying to build UML class diagram. I am a bit new to UML so pardon my ignorance.

I have a domain class User with these attributes:

  • UserName ; data type is string ; identifier
  • Password ; data type is string
  • Active ; data type is bool
  • Locked ; data type is bool
  • PasswordExpiryDate ; data type is DateTime

So this is how I build it in UML:

enter image description here

Now I want to define these operations of this User class in UML class diagram:

  1. Retrieve a User object by a supplied identifier from database.
  2. Match password of the retrieved User object with a supplied password.
  3. Check if the retrieved User is Active.
  4. Check if the retrieved User is Locked.
  5. Check if the retrieved User's password has expired.
  6. Insert a User object in database.
  7. Update a User object in database.
  8. Delete a User object from database.

So this is how I build it in UML:

enter image description here

But I am very confused about method #1 "Retrieve a User object by a supplied identifier from database".
All other methods are working on a single User object which means that single User object has already been retrieved from database or its a new object.
But method #1 make sense to work on a collection of User objects which means all the user objects which already exist in the database.

Does it make sense? or is it a mismatch? If yes how can I fix it?

Thanks


UPDATE

Thanks for mentioning the class-level operations in UML class diagram. I did not know about them.

So I have made the changes and this is the latest UML class diagram for User class:

enter image description here

Is it now correct?


Solution

  • Notice that it's not only your method #1, but also your AddUser method to "work on a collection of User objects which means all the user objects which already exist in the database". In fact, all CRUD methods are distinct as they work on the corresponding database table population.

    With a DAO approach, you would define your CRUD data access methods retrieveUser and deleteUser in the form of class-level ("static") methods since they don't work with a context object (as remarked by Geert Bellekens), but rather take the object ID (in your case UserName) as their only parameter. The other two CRUD methods, createUserand updateUser, would also normally not work with a context object (in your case a User object), but rather have parameters for the data values entered via a user interface. In the case of createUser (your AddUser), a User object would only be created if the data values satisfy all constraints defined in the model class User. In the case of updateUser, an update would only be performed when the changed values do not violate any constraint.