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:
So this is how I build it in UML:
Now I want to define these operations of this User
class in UML class diagram:
So this is how I build it in UML:
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
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:
Is it now correct?
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, createUser
and 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.