Search code examples
umlentity-relationshipclass-diagramerdmultiplicity

UML Class Diagram Multiplicity and ER Diagrams Cardinality


I have a simple question about the multiplicity of the class diagrams and the cardinality of the ER diagrams. They are confusing me on how to choose them. Whether should I choose them from the concept of one instance or the whole system.

For example: A User can create and have many profiles. And These profiles can have only one user. (One to Many) However in general (in the whole system), Profiles can have many users other than this particular user. (Many to Many)

so my question, when i am designing class and ER diagrams should i take it from the perspective of one instance (one user) like the first one or from the whole system perspective. that many users can have many profiles and vice versa?


Solution

  • A User can create and have many profiles. And These profiles can have only one user. (One to Many)

    The class diagram can be :

    enter image description here

    The diagram indicates a given User can have any positive or null number of Profile, and a given Profile is for one and only one User.

    That means an instance of Profile cannot exist without an associated instance of User so the relation can be a composition (when an instance of User disappears its Profiles disappear too) :

    enter image description here

    However in general (in the whole system), Profiles can have many users other than this particular user. (Many to Many)

    The previous diagram is still the right one, it makes no assumption on the total number of instances of User and Profile.

    You can show example of instances through a object diagram :

    enter image description here


    From your remark :

    i will have two classes one named User and one named Modules So Users can enroll into modules, So in that way it will be many to many right? Many users can enroll into modules while modules can have many users, is that right? or should it be also using only one instance? Like A user can enroll into many modules, and these modules can only have one user (one instance)

    Except if the module is dedicated/created for only one given user which is very less probable in that case you have many to many, so the multiplicity is "*" in both sides.