Virtual Classes Logo          Virtual Classes
    Read Anytime,Anywhere

Association

Association is a ("Has A") relationship between two classes.
It allows one object instance to cause another to perform an action on its behalf. Association means two objects are related. If object A has a reference to object B then they are associated. Association is the more general term that define the relationship between two classes. It represents a relationship between two or more objects where all objects have their own lifecycle and there is no ownership.
The name of an association specifies the nature of relationship between objects.
This is represented by a solid line.

Let’s take an example of relationship between CAR and DRIVER
Multiple DRIVER can associate(or drive) with a single CAR and a single DRIVER can associate(can be driven) by multiple DIVER. But there is no ownership between the objects and both have their own lifecycle. Both can be created and deleted independently.

public class CAR
{
public CAR()
{
new DRIVER().Initialize();

}

}


Association example