The difference between Object objects and object reference?

  • (4 Pages)
  • +
  • « First
  • 2
  • 3
  • 4

50 Replies - 4635 Views - Last Post: 29 April 2013 - 07:04 PM Rate Topic: ***-- 2 Votes

#46 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 864
  • View blog
  • Posts: 2,653
  • Joined: 29-July 11

Re: The difference between Object objects and object reference?

Posted 29 April 2013 - 01:26 PM

View Postjon.kiparsky, on 29 April 2013 - 03:29 PM, said:

I think you're a little confused on this. I don't really have time for this, but I don't want to leave your confusion lying around where novice programmers will pick it up, so here goes:

Polymorphism decouples your classes by isolating structure from implementation: If class Foo manipulates a List it doesn't know how that list is implemented.


This is an example of proper encapsulation.

View Postjon.kiparsky, on 29 April 2013 - 03:29 PM, said:

This allows me to replace one List with another, knowing that both have promised to provide the correct results for the methods I'm interested in.


This is the polymorphism portion. There's no confusion on my end. I am not the one claiming that:

"The value of polymorphism lies in the ability to define and use attributes and behaviors without having to know about the details of how those attributes and behaviors are implemented."

is not encapsulation. It is encapsulation.

Now, if it were said that "The value of polymorphism lies in the ability to substitute one TYPE with another, knowing that both have promised to provide the correct results for that type."

Then I'd agree that it is polymorphism, but the design and use of a class without needing to know its internals or how they work is encapsulation, and nothing can ever change that.

This post has been edited by farrell2k: 29 April 2013 - 01:26 PM

Was This Post Helpful? 0
  • +
  • -

#47 RozenKristal  Icon User is offline

  • D.I.C Regular

Reputation: 45
  • Posts: 380
  • Joined: 29-September 12

Re: The difference between Object objects and object reference?

Posted 29 April 2013 - 05:00 PM

Look like there is a very thin line between the two, so, how Oracle define these 2 ideas?
Was This Post Helpful? 0
  • +
  • -

#48 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 864
  • View blog
  • Posts: 2,653
  • Joined: 29-July 11

Re: The difference between Object objects and object reference?

Posted 29 April 2013 - 05:43 PM

View PostRozenKristal, on 30 April 2013 - 12:00 AM, said:

Look like there is a very thin line between the two, so, how Oracle define these 2 ideas?


There is not. They're completely different ideas :) Do some research and tell us what you find. :)
Was This Post Helpful? 0
  • +
  • -

#49 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 8013
  • View blog
  • Posts: 13,719
  • Joined: 19-March 11

Re: The difference between Object objects and object reference?

Posted 29 April 2013 - 06:55 PM

View PostRozenKristal, on 29 April 2013 - 07:00 PM, said:

Look like there is a very thin line between the two,


No, they're quite different. The confusion is arising because the ordinary language meaning of "encapsulation" can be applied, without too great a stretch, to what happens when you use polymorphism. However, the ordinary language meanings are not very interesting here. They are suggestive, but not definitive.

The technical uses of the terms are simple enough. To quote from one java text which happens to be on my shelf:

Quote

We should make it difficult, if not impossibl, for code outside of a class to "reach in" and change the value f a variable that is declared inside that class. This characteristic is called "encapsulation"


This is what the term means, and it's what people mean when they use the term.

Polymorphism, on the other hand, is that ability of a reference to point to different sorts of objects. One way in which this is accomplished - the main way in Java - is by inheritance or interface implementation. A reference declared as pointing to an Animal can refer to a Horse or a Snake or a Wombat object - standard stuff.

Notice that this does not encapsulate anything at all. Those classes are free to leave everything about their data wide open. In fact, in an inheritance relationship, I can require that they leave data open, by declaring it in the superclass. This does open up the potential for encapsulation: now Wombats are in a position to encapsulate data if they wish. But in itself, it is not an example of encapsulation.

Does this clarify things?

This post has been edited by jon.kiparsky: 29 April 2013 - 06:56 PM

Was This Post Helpful? 0
  • +
  • -

#50 RozenKristal  Icon User is offline

  • D.I.C Regular

Reputation: 45
  • Posts: 380
  • Joined: 29-September 12

Re: The difference between Object objects and object reference?

Posted 29 April 2013 - 06:59 PM

perfectly clear now :) Thank you. It is fun to see my original question turn into a good debating :P
Was This Post Helpful? 0
  • +
  • -

#51 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 8013
  • View blog
  • Posts: 13,719
  • Joined: 19-March 11

Re: The difference between Object objects and object reference?

Posted 29 April 2013 - 07:04 PM

Glad I could help - it's always worthwhile to get clear on these things.

The important thing though is not so much the name as the thing. If you don't understand why it's important to protect your objects' data against intrusive meddling, knowing that this protection is called "encapsulation" (and not "polymorphism") does you little good.
Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • « First
  • 2
  • 3
  • 4