• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Navigable properties

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Cameron,

Thanks for your great book. By far better than the Mc Graw Hill. I know because I have read that one first.
Especially the Association part. I did not find that in "Head First 5" and not in "Mc Graw Hill". So keep doing the good work!

Concerning page 134.

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)

If I choose the first: I do have twice the same methods in different classes. Is this correct?
When do I place the methods in the Supplier class and when do I place those methods in the Address class?


Thanks in advance for your reply.

Rene'
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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(){...}


 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll quite often see two classes with the same sets of methods. That's completely normal, and completely correct. After all, a person and a supplier might share the same address. Both point to the same data in memory, so only the methods are duplicated, but the data is all stored in the same place, so it's efficient.

You wouldn't put set and get Address in the Address class. The address already knows about itself. It's others that use it that need to updated it and perhaps change it.

-Cameron McKenzie
reply
    Bookmark Topic Watch Topic
  • New Topic