educative.io

Understanding of one/two way associations

Cinemas has City Class
City has List of Cinema class
How and Why is this one way association


Course: Grokking the Low Level Design Interview Using OOD Principles - Learn Interactively
Lesson: Class Diagram for the Movie Ticket Booking System

Hi @Psbdassani !!
This one-way association between the Cinema class and the City class is established to reflect the relationship between these entities in the movie ticket booking system. Let’s break down how and why this association is implemented:

  1. One-Way Association:

    • In a one-way association, one class (the source) knows about the other class (the target), but not vice versa. In this case, the Cinema class knows about the City class, but the City class doesn’t necessarily need to know about individual cinemas within it.
  2. Implementation:

    • The Cinema class has a reference to the City class, indicating that each cinema is associated with a specific city.
    • However, the City class does not have a direct reference to individual cinemas. Instead, it maintains a list of cinemas within the city. This list allows the city to access information about the cinemas it contains, but it does not establish a direct link from a city to an individual cinema.
  3. Reasoning:

    • In the context of a movie ticket booking system, it makes sense for a cinema to be associated with a city because cinemas are physical locations situated within cities. Therefore, it’s logical for each cinema to have a reference to the city it is located in.
    • On the other hand, cities do not necessarily need to have direct knowledge of individual cinemas within them. A city may have numerous cinemas, but it may not require detailed information about each cinema’s operations or attributes. Instead, it’s more practical for a city to maintain a list of cinemas within its boundaries for administrative purposes or to provide information to users.
  4. Benefits:

    • This one-way association simplifies the relationship between cities and cinemas within the movie ticket booking system. It ensures that the responsibilities and dependencies between these entities are appropriately managed.
    • By establishing a one-way association from cinema to city, the system architecture remains flexible. It allows for easy retrieval of information about the city associated with a particular cinema while keeping the city class lightweight and focused on its core responsibilities.

Overall, implementing a one-way association between the Cinema class and the City class provides a clear and efficient way to model their relationship within the movie ticket booking system.
Happy Learning :blush: