Is it ok to initialize an attribute (Addresses) of a Value Object while declaring that attribute.
eg Suppose I define a value object named Customer like this
public class Customer implements Serializable
{
private String firstName;
private String lastName;
private Collection Addresses = new ArrayList();
public Collection getAddresses()
{
return Addresses;
}
public String getFirstName()
{
return firstName;
}
public String getLastName()
{
return lastName;
}
public void setAddresses(Collection addresses)
{
Addresses = addresses;
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public void setLastName(String lastName)
{
this.lastName = lastName;
}
}
Is this correct or shall I use constructor to explicetly initialize my attribute Addresses with ArrayList ?
eg Suppose I define a value object named Customer like this
public class Customer implements Serializable
{
private String firstName;
private String lastName;
private Collection Addresses = new ArrayList();
public Collection getAddresses()
{
return Addresses;
}
public String getFirstName()
{
return firstName;
}
public String getLastName()
{
return lastName;
}
public void setAddresses(Collection addresses)
{
Addresses = addresses;
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public void setLastName(String lastName)
{
this.lastName = lastName;
}
}
Is this correct or shall I use constructor to explicetly initialize my attribute Addresses with ArrayList ?