Problem Analysis  «Prev  Next»
Lesson 9Basic object modeling: multiplicity
ObjectiveDefine multiplicity as it applies to basic object modeling.

Basic Object Modeling using Multiplicity

Multiplicity in basic object modeling in **Unified Modeling Language (UML)** specifies how many instances of one class can be associated with a single instance of another class. It defines the quantitative relationship between objects, essentially indicating the cardinality of the association.
Key Points About Multiplicity:
  1. One-to-One (1..1):
    • One object of Class A is associated with exactly one object of Class B.
    • Example: A person has exactly one passport.
  2. One-to-Many (1..*):
    • One object of Class A is associated with multiple objects of Class B.
    • Example: A teacher teaches many students.
  3. Optional (0..1):
    • An object of Class A may or may not be associated with an object of Class B.
    • Example: A customer may have a membership card.
  4. Many-to-Many (0..*, 1..*):
    • Multiple objects of Class A can be associated with multiple objects of Class B.
    • Example: Students enroll in many courses, and courses have many students.

Examples of Multiplicity:
  1. One-to-One (1..1):
    • One object of Class A is associated with exactly one object of Class B.
    • Example: A person has exactly one passport.
  2. One-to-Many (1..*):
    • One object of Class A is associated with multiple objects of Class B.
    • Example: A teacher teaches many students.
  3. Optional (0..1):
    • An object of Class A may or may not be associated with an object of Class B.
    • Example: A customer may have a membership card.
  4. Many-to-Many (0..*, 1..*):
    • Multiple objects of Class A can be associated with multiple objects of Class B.
    • Example: Students enroll in many courses, and courses have many students.

Importance in UML: Multiplicity clarifies the constraints and relationships between objects in a system. It helps developers understand the data structure, relationships, and rules, ensuring consistency in design and implementation.

Refactoring

Multiplicity

To complete each association, you need at least to assign multiplicity. Multiplicity simply means the number of objects that participate in the association. Assign two separate values, one at each end of the association. Ask the question
"How many objects of this class are associated with one object of the other class?"
Then switch to the other end of the association and ask the question again.
An example of multiplicity Using the course project example again, you would ask "How many seats can be held by one customer?" If the answer is none or a lot, show this by placing the multiplicity 0..* on the Seat end of the holds association.
How many seats can be held by one customer?
How many seats can be held by one customer

Next Question: Your next question would be, "How many customers can hold the same seat?"
To answer this question, you have to choose a time frame. Remember the three questions used for abstraction.
  1. What is the context?
  2. What time frame do we need to support?
  3. How much detail do we need to support?

Let us go with a point in time for this example.
In that case, the answer would be "one at a time." The multiplicity would be 0..1: No one or only one customer may hold the same seat at the same time.
How many customers can hold the same seat?
How many customers can hold the same seat?

SEMrush Software Target 9SEMrush Software Banner 9