views:

45

answers:

1

Bloch said: Provide Programmatic Access to All Data Available in String Form.

I am wondering if he means to override toString() which should involve 'all data available'?

I think the 'in string form' means that the string is for human reading, so override toString() is enough for the advice. Am I correct?

+7  A: 

No, apparently he meant quite the opposite of that. If a data member is available as part of the toString() output (or other string methods of the class), Bloch's fear is that developers using the API will rely on that and parse the strings to get at the underlying data values. His advice is to provide specific accessors for those data elements, to prevent developers from relying on the format of toString()'s output.

Carl Manaster
Very clear explanation! Thanks!
卢声远 Shengyuan Lu
perfect, Thanks
mohammad shamsi