• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

objects and references

 
le taylom
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic