aspose file tools*
The moose likes Java in General and the fly likes objects and references Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "objects and references" Watch "objects and references" New topic
Author

objects and references

le taylom
Ranch Hand

Joined: Dec 01, 2000
Posts: 44
Hi Guys,
This is a post to solidify my understanding and hopefully get some discussion comments back.
I have a class, call it MyClass, and I declare a reference variable to an object with class-scope:

Within some other method, methodA, in my class I call methodB, and within methodB I instantiate the reference to myObject. Then from within methodA I call methodC, and use the object (calling its methods etc):


So, is this the most object-oriented efficient way to do this?
Or is the most OO efficient way to do it like so:
Do not declare a reference with class-scope. Instead pass the reference of the object between the methods by copying the refernce into newly created objects:

What are the pros and cons of the two approaches?
Particularly the implications if I make changes to an object reference I have passed into another method etc.....
TIA
T
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

The first method is the best method. BUt its not a question of object orientation or not. there is no need to pass around that variable. But for object orientatino you may have something like this.
 
wood burning stoves
 
subject: objects and references
 
Similar Threads
Exeption Handling
EASY MOCK
synchronization basics
decision of member variables?
Creating another Instance of same Session EJB