1

I am currently learning to create uml diagram, especially class diagram and have some multiple difficulties understanding some concept in the process, here is the question

  1. Does multiplicity always 2 sided? like when i have this classes, PP class is the buyer Class, and Cart is the class to save the buyer order info, i assign 1 - 1 multiplicity because 1 buyer would always have 1 cart vice versa, in Cart it is clearly defined (in my code) that i have a variable with type PP, but inside class PP there is no cart variable at all, so does the multiplicity wrong? should i just assign 1 sided multiplicity in PP and have none in Cart? or does having the variable inside class is not important? i am quite confused on understanding this

enter image description here

  1. About dependency relationship, if i have this PP class which have variable shippingAddress inside the class and using data type ShippingAddress as parameter in some of the function, should i used dependency relationship or association

enter image description here

Thanks a lot

Jolzal
  • 547
  • 7
  • 19

2 Answers2

2

qwerty_so already provided a concise and accurate answer. Nevertheless, I'd like to add some more thoughts to complete the picture.


1

In an association there are always at least 2 sides, and there is a multiplicity on each side: The first diagram says that a PP always has 1 Cart and the Cart always 1 PP. If you meant "sometimes" instead of always, change it to 0..1

There can be more than 2 sides in an n-ary association: Then you'll have n multiplicities.

WHen in a diagram there is no multiplicity indicated on one side, it doesn't mean that there is no multiplicity, but that we don't know what the multipliity is (or that it's not important for what we want to show in the diagram).

Now your question about multiplicity and how to implement it raises another topic:

it is clearly defined (in my code) that i have a variable with type PP, but inside class PP there is no cart variable at all, so does the multiplicity wrong?

It's the question of navigability: If in the implementation of Cart you have a PP variable, this means that you can easily navigate from the a given Cart to the associated PP. If you don't have a Cart variable in the PP implementation, it is difficult to find the corresponding Cart, so it's not navigable. Navigability is shown with an open arrow.

Multiplicity and navigability are two orthogonal concepts.


2

If you have both a dependency and an association, you'd usually show the association. There is no need to also show the dependency, since it is implied by the association. However it's not wrong if you want to show both (but with a dashed line and open arrow) (for example, if you want to add some explanatory comments for each).

Now if in the PP implementation you have a ShippingAddress, it's not only a question of navigability, but it's also a question of ownership of the association end. So you can use the dot notation on the side of the ShippingAddress.

If you don't have an association, but use another class as parameter or return type of an operation, then you may want to show s simpe «use» dependency.

Christophe
  • 68,716
  • 7
  • 72
  • 138
  • Thankyou for such a clear answer, the navigability part really got me so in my case i need to use arrow pointed at PP ? , i still dont quite get the ownership of the association end meaning here if my PP class have shippingaddress as attribute does it not count as navigability also? why is it ownership? im sorry i cant quite hold the concept yet – Jolzal Jan 08 '21 at 17:05
  • Indeed, ownership of the association-end implies navigability. Ownership of the association-end is about semantics. Navigability is a guaranty about run-time efficiency. It's about two different concerns which are not mutually exclusive. – Christophe Jan 08 '21 at 18:54
1
  1. Multiplicity is defined where needed. If it's not given then it's undefined and could be anything from zero to infinity. It depends whether you define that. One reason is simplicity, if you want to just show "it's associated". For a complete model (if that is needed) you have to specify multiplicities at all edges.

  2. Dependency is just a weak relation. If you use some class only in parameters or as pass-through you use a dependency relation. Your 2nd picture would be wrong as you should draw the dependency (dashed line with open arrow) downwards since PP uses/depends on ShippingAddress and not the other way around.

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
  • thankyou so much for answering, so for the first answer what i may be misundestood is what is the meaning of associated? like if in my class Cart code i have variable PP , but in my class PP i dont have the variable to know that PP is associated to Cart, is this considered associated with multiplicity 1-1? and for 2nd question PP class actually have attribute of Shipping address inside and also passing Shippingaddress as parameter inside a function, should i use dependency or association for this? – Jolzal Jan 07 '21 at 15:05
  • No and no. Neither has Cart a named property nor does ShippingAddress have one. Either add properties or use role names. – qwerty_so Jan 07 '21 at 16:34