how come the classes you have mentioned have one way and two way association?
Hi @Geet_Aggarwal !!
In a class diagram, associations represent relationships between classes. These associations can be one-way or two-way, depending on whether the relationship is navigable in one direction or both directions between the connected classes.
-
One-way association(Unidirectional association):
In a one-way association, the relationship is navigable from one class to another but not vice versa. It means that one class knows about the other class, but the other class does not necessarily know about the first class.Example of one-way association:
ClassA -----> ClassB
In this example, ClassA is associated with ClassB, but ClassB doesn’t have a direct association back to ClassA.
-
Two-way association(Bidirectional association):
In a two-way association, the relationship is navigable in both directions between the connected classes. It means that both classes know about each other and have a direct connection.Example of two-way association:
ClassA <----> ClassB
In this example, ClassA is associated with ClassB, and ClassB is also associated with ClassA. Both classes can access each other through this association.
To further illustrate, let’s consider a real-world example:
Imagine you have two classes: Person
and Address
.
-
One-way association:
APerson
class can have an attribute representing their homeAddress
. ThePerson
class knows about theAddress
class (one-way association) to store the address information, but theAddress
class doesn’t necessarily know which person it belongs to. -
Two-way association:
In a two-way association, theEmployee
class has an attribute calledcompany
, which stores the reference to theCompany
the employee belongs to. Conversely, theCompany
class maintains a list of employees associated with it through an attribute calledemployees
. This allows bidirectional navigation, as eachEmployee
knows itsCompany
, and eachCompany
knows its list ofemployees
.
I hope it helps. Happy Learning