Association in OOP with Visual Basic .NET

Association shows the relationship between classes

There are two types of Associations
1 Unary Association
2 Binary Association

1. Unary Association

Class A does not know about ClassB
Class B knows about ClassA

To indicate the Unary Association single head arrow is used as shown in the below figure

Now lets look at the following example
You can see the Person and Address relationship below. We call this relationship as has-a relationship since person has a address

So Person knows the address but address does not know anything about person

Now lets see how we can implement this Person and Address association in VB.NET

In Visual Studio, you can draw the UML diagram  as shown in the below figure

You can see that Person class has attribute for the Address Class

Address Class

Person Class

In this example, Person class has Address attribute and it will show you the unary association

2. Binary Association

In Binary association, Class A knows Class B and Class B knows Class A

To indicate the Binary Association simple line is used as shown in the below figure

Now we can see the Teacher and Course relationship in the following UML diagram

Here, teacher knows the course and course knows the teacher

Now we will see how you can implement bi-directional association with VB.NET

Course Class

Teacher Class

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *