This is yet another follow up question about Object oriented design in general. I am trying to break them down to separate questions per advice I got from @Jay earlier.
I get a new question, almost every step of the OO design process. I tried to get the ideas from books, articles and the web. It just gets more muddied up. I would like to get some advice from the experts here, so I can get my concepts right.
Say I have the below Objects:
public class AddressRecord {
protected String addressLine1;
protected String addressLine2;
protected String city;
protected String state;
protected String postalCode;
protected String country;
....
}
public class AddressValidationRequest {
private AddressRecord addresses[];
protected ArrayList actions;
protected ArrayList columns;
protected Properties options;
...
}
Should I keep AddressRecord completely hidden inside Request (is it Aggregation?) or expose and access the AddressRecord from outside (Composition)?
(To me, even inheritance seemed like an option to extend AddressRecord to a Request, though I feel they are distinct entities in real world, so I dropped that idea).
What I mean is, should I have AddressRecord as a private object inside Request and add getters/setters in the Request itself for each field in AddressRecord?
Or just add getter/setter to get/set AddressRecord[] from the Request and then set it up outside, say in a controller code?
(This later idea I got when I tried to extract the AddressRecord class from Request in Eclipse like below:
public class AddressSearchRequest {
AddressRecord address;
public AddressSearchRequest(String format, String customerId, String addressLine1, String suite,
String city, String state, String postalCode) {
this.format = format;
this.customerId = customerId;
this.address.setAddressLine1(addressLine1);
this.address.setAddressLine2(Suite);
this.address.setCity(city);
this.address.setState(state);
this.address.setPostalCode(postalcode);
}
public void setAddressLine1(String addressLine1) {
this.address.setAddressLine1(addressLine1);
}
public String getSuite() {
return address.getAddressLine2();
}
public void setSuite(String suite) {
this.address.setAddressLine2(suite);
}
public String getCity() {
return address.getCity();
}
public void setCity(String city) {
this.address.setCity(city);
}
public String getState() {
return address.getState();
}
public void setState(String state) {
this.address.setState(state);
}
public String getPostalCode() {
return address.getPostalCode();
}
public void setPostalCode(String postalCode) {
this.address.setPostalCode(postalCode);
}
}
UPDATE:
There are actually 2 different types of Requests I am dealing with - a Search Request - takes only one address and may return multiple matches.
A Validation Request may take one or more addresses.
I had them both as Request causing some confusion. corrected it.
Note: I am using AddressRecord also in other types of Request(s) and Response classes.