Aggregation, Association and Composition (examples of code given)
- by Bukocen
I have such a simple example:
public class Order
{
private ArrayList<Product> orders = new ArrayList<Product>();
public void add(Product p)
{
orders.add(p);
}
}
Is it aggregation or composition?
I guess it's composition, because orders will be delated after delete of Order, right?
Unfortunately it was a task and answer was different;/ Do you know why?
second problem:
public class Client extends Person
{
String adress = "";
Orders orders = new Orders();
public Client(String n, String sn)
{
name = n;
surName = sn;
}
public String getAddress()
{
return adress;
}
public Orders getOrders()
{
return this.orders;
}
}
Is it Association between Client and Orders?
My teacher told me that this is association, but I was wondering why it's not a aggregation/composition - he told me that aggregation or composition occur only when one class contains few instances of different class - is that right? I guess not, because e.g. car contains ONE wheel and it's aggregation I guess?
What type of relation is that and why?
Greetings