aspose file tools*
The moose likes Beginning Java and the fly likes Convention for displaying class data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Convention for displaying class data" Watch "Convention for displaying class data" New topic
Author

Convention for displaying class data

Charles Bradley
Greenhorn

Joined: Oct 04, 2009
Posts: 25
Many classes contain methods that display the data in the object. Is there a convention for the names of methods that provide various levels of detail? For example, consider a class called Point containing floats for x and y coordinates of the point. One method might display "2.0, 3.0" and another might display "(x=2.0, y=3.0)". A more complicated class might have several formats.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

None that I'm aware of.

The toString() method is usually used to create a human-readable string representation of the object, but the level of detail is up to the person overriding it. Anything beyond that is at the programmer's discretion. For example, for a detailed representation I usually use something like dump(). You could also create a method that takes an enum that defines granularity, similar to logging levels.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

If you're really feeling bold you can write your own Format subclass.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Convention for displaying class data