Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / August 2005

Tip: Looking for answers? Try searching our database.

Passing references

Thread view: 
Brian Fox - 10 Aug 2005 17:18 GMT
Hi -

What's the general contract/expectations for passing objects?  Is the method
receiving the reference expected to copy the object if it might modify it?

Let's say a method receives a buffer and needs to modify that buffer.  Is it
an okay practice to note in the javadoc that the caller needs to provide a
disposable data buffer?

reverseBuffer(capitalizeBuffer(padBuffer(someBuffer))) generates a lot of
waste if each method is expected to work with a scratch copy.

I know there's no language rules here.  But I'm curious how people handle
the issue.  Are there any guidelines?

Thank you,
Brian
Boudewijn Dijkstra - 12 Aug 2005 17:33 GMT
> Hi -
>
> What's the general contract/expectations for passing objects?  Is the method
> receiving the reference expected to copy the object if it might modify it?

If the object doesn't want to be modified, then it should simply not allow
that.

> Let's say a method receives a buffer and needs to modify that buffer.  Is it
> an okay practice to note in the javadoc that the caller needs to provide a
> disposable data buffer?

If the object is modifiable, then IMHO it would be good to know what a method
does to it.

> reverseBuffer(capitalizeBuffer(padBuffer(someBuffer))) generates a lot of
> waste if each method is expected to work with a scratch copy.

Luckily in the JVM all waste can be cleaned up.

> I know there's no language rules here.  But I'm curious how people handle
> the issue.  Are there any guidelines?

As a non-professional, I usually figure it out as I go along.  Finishing your
first design is a good time to start your second design.  :)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.