I understand how to do composition but I have never done with lists, although the principle should be the same, I do not understand how to do it.
To start I have a class CentroComercial
that has a ArrayList
called lojas
which will pass by attribute in construtor
.
Lojas
is a ArrayList
that stores objects of type Loja
. being this super-class divided into several subclasses. And I have two doubts.
How do I do the
public void setLojas(ArrayList<Loja> lojas) {}
What is the best way to instantiate Arraylist?
private ArrayList<Loja> lojas;
private ArrayList<Loja> lojas = new ArrayList<Loja>();
or some other way?