• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

direct/indirect References in Objects

 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where lies the difference between this:



and this:



In both cases, the mouse-property of name is set in Object Cat. Which one is better? differences?
 
Ranch Hand
Posts: 67
Mac Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is there in both classes?
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Work this out with a pencil and paper: What is the Mouse object in the cat before and after each bit of code? Then you can see whether there is a significant difference or not. And by "w" did you mean "m"?

Some people like lots of invocations joined together by dots, some don't. It depends on what the methods return; if they return an object reference, you can use join-the-dots invocations, if they are void you can't.
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello, yes I mean m instead of w.

In both cases, the Mouse-Object of Cat are changed.

This is obvious:



But this not:



So I guess, I prefer the direct way:



It s clearer.
 
Dhruva Mistry
Ranch Hand
Posts: 67
Mac Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nimo frey wrote:hello, yes I mean m instead of w.

In both cases, the Mouse-Object of Cat are changed.

This is obvious:



But this not:



So I guess, I prefer the direct way:



It s clearer.



it seems to me that
if we need value getting from Cat object,


if we need to insert new/different value than Cat object,


i think no change in performance if values to be set is equal as


am i rightly thinking?

 
Campbell Ritchie
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure; I think you need to try that code out in different contexts. I am not sure "direct" and "indirect" are quite the right words to use.

I think what you have here are "aliases": two names for the same object. You can say m.setName("Jerry") or c.getMouse().setName("Jerry").
You will have to try different combinations, and m.getName() or c.getMouse().getName(). I think you will find that m.setName("Jerry") followed by c.getMouse().getName() will return "Jerry".
Getting two different names for the same object can cause no end of confusion because you forget that calling a method on m also affects c.getMouse().

I think it is a case of what is easier to read, and I don't think there will be a performance difference.
 
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:I think it is a case of what is easier to read, and I don't think there will be a performance difference.


+1
 
Dhruva Mistry
Ranch Hand
Posts: 67
Mac Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

think it is a case of what is easier to read, and I don't think there will be a performance difference.



nimo asked for difference

for sure, is more readable than

but, is there any performance related difference if 'm' is used instead of


 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I think it is a case of what is easier to read, and I don't think there will be a performance difference.





and I don't think there will be a performance difference.



I hope so:-)
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic