0% found this document useful (0 votes)
93 views3 pages

Difference Between Association

The document discusses the differences between association, aggregation, and composition relationships. Association represents a weak relationship where objects have independent lifecycles and no owner. Aggregation also involves independent objects but implies some ownership, such that deleting the container does not require deleting contained objects. Composition represents a strong relationship where the contained objects have dependent lifecycles and are owned by the container, so deleting the container deletes contained objects.

Uploaded by

kishore
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views3 pages

Difference Between Association

The document discusses the differences between association, aggregation, and composition relationships. Association represents a weak relationship where objects have independent lifecycles and no owner. Aggregation also involves independent objects but implies some ownership, such that deleting the container does not require deleting contained objects. Composition represents a strong relationship where the contained objects have dependent lifecycles and are owned by the container, so deleting the container deletes contained objects.

Uploaded by

kishore
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Difference between Association, Aggregation and

Composition

Association:----

Association is a semantically weak relationship (a semantic


dependency) between otherwise unrelated objects. An
association is a "using" relationship between two or more
objects in which the objects have their own life time and there
is no owner. As an example, imagine the relationship between
a doctor and a patient. A doctor can be associated with
multiple patients and at the same time, one patient can visit
multiple doctors for treatment and/or consultation. Each of
these objects have their own life-cycle and there is no owner.
In other words, the objects that are part of the association
relationship can be created and destroyed independently.

// Java program to illustrate the


// concept of Association
import java.io.*;

// class bank
class Bank
{
private String name;

// bank name
Bank(String name)
{
this.name = name;
}

public String getBankName()


{
return this.name;
}
}

// employee class
class Employee
{
private String name;

// employee name
Employee(String name)
{
this.name = name;
}

public String getEmployeeName()


{
return this.name;
}
}

// Association between both the


// classes in main method
class Association
{
public static void main (String[] args)
{
Bank bank = new Bank("Axis");
Employee emp = new Employee("Neha");

System.out.println(emp.getEmployeeName() +
" is employee of " + bank.getBankName());
}
}
Run on IDE
Output:

Neha is employee of Axis

Aggregation:------

The Aggregation is the week-association, if whenever the container object destroyed, They is
no guaranty destruction of contained objects ie, without existing the container object they
may be a changes of existing of contained objects ie, container object is just maintained the
references of the contained objects
Aggregation is a specialized form of association between two
or more objects in which the objects have their own life-cycle
but there exists an ownership as well. Aggregation is a typical
whole/part relationship but it may or may not denote physical
containment -- the objects may or may or be a part of the
whole. In aggregation the objects have their own life-cycle but
they do have ownership as well. As an example, an employee
may belong to multiple departments in the organization.
However, if the department is deleted, the employee object
wouldn't be destroyed. Note that objects participating in an
aggregation relationship cannot have cyclic aggregation
relationships, i.e., a whole can contain a part but the reverse is
not true. In the following code example, an aggregation
relationship is evident between the IDGBlogAuthor and
IDGBlogAccount classes.

You might also like