René van der ven wrote:
Example is about
Customer(name, gender, income age, Address, getAddress, setAddress)
Address(street, city, state, country)
If I extend your example with Supplier
Where do I place the getAddress and setAdress methods.
Supplier(name, gender, income age, Address, getAddress, setAddress)
or
Address(street, city, state, country, getAddress, setAddress)
Think about this conceptually.
Does a Customer have an address? In literal terms, does he have a physical residency that something is being delivered?
Does a Supplier have an address? In literal terms, does he have a physical place of business that he sends his products from, or that a Customer sends his payment to?
The answer to both of those is Yes.
And would it make sense for an address to getAddress() or setAddress()? You're asking the class to set itself and get itself.
An Address would have methods like:
public void setStreet(
String streetName){...}
public String getStreet(){...}
public void setZipCode(String zipCode){...}
public String getZipCode(){...}