I'm a little bit confused on what is the right way to use setters.
Is the preferable method to create a setters with only 1 parameter of the same object type like this one ?
public void setWebsite(String website) {
if(website ==null){
this.website = "";
}else {
this.website = website;
}
}
But i have 2 setters where i'm doubting about
public void setAddressClientList(List<AddressClient> addressClientList,Client client) {
//Here we add the customer to the address
if (!addressClientList.isEmpty()) {
for (AddressClient addressClient : client.getAddressClientList())
{
addressClient.setClient(this);
this.addressClientList.add(addressClient);
}
}
}
and
public void setProfessional(String companyName,String vatNumber ) {
this.professional = !(companyName == null || vatNumber == null);
}
this is the constructor
public Client(Client client,Company company,Client lastInsertClient) throws ClientException {
setCompany(company);
setActive(true);
setCustomField(client.customField);
setWebsite(client.website);
setVatNumber(client.vatNumber);
setPhoneNumber(client.phoneNumber);
setCurrency("notImplementedYet");
setFaxNumber(client.faxNumber);
setCompanyName(client.companyName);
setSalutation(client.salutation);
setLastName(client.lastName);
setEmail(client.email);
setFirstName(client.firstName);
setClientNumber(lastInsertClient);
setProfessional(client.companyName,client.vatNumber);
setAddressClientList(client.addressClientList,client);
}
Can someone explain if this what the best way to use the setters. And if the last 2 setters are not correct what would you suggest ?
clientever used insetAddressClientList? If not, why pass it as a parameter?setProfessionalis a confusing-looking method. It looks like a private method which should be called fromsetCompanyName(companyName)andsetVatNumber(vatNumber)- and then it could maybe rely upon the member variables rather than have them passed explicitly (because it's easy to callsetProfessional(vatNumber, companyName)(reversing the parameters) by mistake).public void A(int r, int g, int b, int h, int s, int v){...}is hard to remember which parameters are which).