Agregession Vs Comosition.
Hi Folks......
There Are two ways of Creating of classNPSHistory
1>By calling the Constructor of Another class
2> By Calling the Method
Here We are Importing the ClassNPSHistory
Which is the Correct Way for Agregestion and Composition
/////Case 1 For Composition////////
public NRICallHistoryJBean(){NPSHistory aObj)
aObj=new NPSHistory();
}
/// Is this Composition
/////2 Case For Aggregation//////////////////
public NPSHistory amethod(NPSHistory aNPSHistory)
{
aNPSHistory=new NPSHistory();
}
[892 byte] By [
rajpuniaa] at [2007-10-3 1:18:10]

Composition means that composite object can't exist outside compositor. So is better to use constructor for Composition
public class NRICallHistoryJBean {
private NPSHistory history;
public NRICallHistoryJBean() {
history = new NPSHistory();
...
}
.....
}
and doesn't provide set/get methods for this field.
Aggregation is less restricted whole-part relationship. So you can use both constructor or setXXX method to initialize field and getXXX to retrieve it.
Like this
public class NRICallHistoryJBean {
private NPSHistory history;
public NRICallHistoryJBean(NPSHistory aObj) {
history = aObj;
...
}
public void setNPSHistory(NPSHistory aObj) {
history = aObj;
}
public NPSHistory getNPSHistory() {
return history;
}
.....
}
I hope this helps you.
Calling a thing composition is more about how you are using the object than how you created the relationship.
A basket can have a bunch of apples in it. This is aggregation. (in the sense that the weight of the basket is changed because of the presence of the apples.)
A basket can be made from a bunch of straw. This is composition.