educative.io

Why ? How to come up with the association ? Explain

The class diagram has the following association relationships:

  • The ParkingSpot has a one-way association with Vehicle.
  • The Vehicle has a one-way association with ParkingTicket.
  • The Payment has a two-way association with ParkingTicket.

Course: Grokking the Low Level Design Interview Using OOD Principles - Learn Interactively
Lesson: Class Diagram for the Parking Lot - Grokking the Low Level Design Interview Using OOD Principles

Hi @Thirumavalavan !!
In the context of designing class associations in a class diagram for a parking lot system, the associations = are established based on the relationships and interactions between the various classes within the system. Let’s break down these associations and explain how they are determined:

  1. The ParkingSpot has a one-way association with Vehicle:

    • This association represents the relationship between a parking spot and a vehicle that occupies it.
    • In a parking lot system, each parking spot is associated with the vehicle parked in it.
    • It is a one-way association because the parking spot needs to know which vehicle is occupying it, but the vehicle doesn’t necessarily need to know which spot it is in.
  2. The Vehicle has a one-way association with ParkingTicket:

    • This association signifies the connection between a vehicle and the parking ticket issued to it.
    • When a vehicle parks in a spot, a parking ticket is generated to keep track of the parking duration and payment status.
    • It is a one-way association because the vehicle needs to be associated with its parking ticket, but the parking ticket doesn’t need to reference the vehicle.
  3. The Payment has a two-way association with ParkingTicket:

    • This association denotes the interaction between a payment and the parking ticket associated with it.
    • A payment is made for a specific parking ticket to settle the parking fee.
    • It is a two-way association because both the payment and the parking ticket need to reference each other. The payment needs to be linked to the ticket it’s paying for, and the ticket needs to be linked to the payment made.

These associations are established to represent the flow of information and interactions between the classes in the parking lot system. They help in understanding how different components of the system are connected and work together to achieve the functionality of the parking lot, including vehicle parking, ticketing, and payment processing.

The determination of associations is typically based on the requirements and interactions specified for the system. It involves analyzing how different classes collaborate and exchange information to fulfill the system’s functionality. In the context of object-oriented design, associations are a crucial aspect of modeling the relationships between objects and classes within a software system.
I hope it helps. Happy Learning :blush:

1 Like

@Javeria_Tariq I was looking at class diagram in the lesson section, which doesnot show the association in the diagram… there should be “has a” relationship between parking spot and vehicle… but its missing in diagram

Hi @Kapil_Pothakanoori,

Association in object-oriented programming refers to the relationship between classes. To represent the association, we often use the ‘—>’ sign, as illustrated in the figure titled: ‘The class diagram of the parking lot system.’ I recommend revisiting the lesson for a clearer understanding. Additionally, If you have any concerns, feel free to let me know.

I hope it helps. Happy Learning :blush: