Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+17 votes

What exactly does multiplicity mean and how is it properly used in UML diagram?
So if a BankClass has object type of MoneyClass, would BankClass have multiplicity of 0 or more for MoneyClass?

asked in CSC305 Fall 2022 by (1 point)
+4

Just wondering whether multiplicity does include many-to-one or many-to-many relationship

2 Answers

+9 votes

Multiplicity just shows how many instances of an object another object would have, so yeah, a BankClass would have a 0 or more multiplicity for MoneyClass.

answered by (1 point)
+5

I'm not quite sure why a "Bank" class would have a "Money" class... or what their relationship would be. Couldn't we just store the money as a number, instead of as a custom object?

(Side note: if you've taken CSC 330 already, and are worried about precision/rounding issues with doubles, then using a long integer and storing the number of cents rather than using a double storing the number of dollars turns out to be a better design choice... but I digress.)

If we want to store different types of money, then you might want a "Currency" class to represent USD, euros, Japanese yen, etc.

Perhaps a clearer example would be a Bank class that contains a list of BankAccount objects (or a Map that maps name Strings to BankAccount objects). In this case, it would be a 1-to-many relationship.

+9 votes

Multiplicity is the one-to-one or one-to-many relationship between classes. If a class has several methods that uses the other class, or has a list of items of the other class, then its one to many otherwise if its one to one.

answered by (1 point)
+4

Mostly right, but having "several methods that use the other class" doesn't necessarily constitute "1 to many". You often want to look for class A having a Collection (List, Set, Map, etc) of B objects within it.

...