The difference between Object objects and object reference?

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4

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

#31 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: The difference between Object objects and object reference?

Posted 25 April 2013 - 07:24 PM

View PostFlukeshot, on 25 April 2013 - 10:16 PM, said:

I think the main point and Ockham's razor of the topic is that an object is an object, while an object reference is a reference/pointer.

As an object object is not directly accessible in Java the point is useless

Quote

Object o1 = new object(); //created one object
Object o2 = o1; //assigned 2 references



Changing a value of o2 will be reflected in o1.


Yes in Java all objects are object pointers so o1 and o2 are not object but object pointers. So no need to discuss what could had happenned if Java Engineering had done it a different way
Was This Post Helpful? 0
  • +
  • -

#32 Flukeshot  Icon User is offline

  • A little too OCD
  • member icon

Reputation: 416
  • View blog
  • Posts: 1,030
  • Joined: 14-November 12

Re: The difference between Object objects and object reference?

Posted 25 April 2013 - 07:24 PM

It was a nice question.
Was This Post Helpful? 0
  • +
  • -

#33 RozenKristal  Icon User is offline

  • D.I.C Regular

Reputation: 45
  • View blog
  • Posts: 343
  • Joined: 29-September 12

Re: The difference between Object objects and object reference?

Posted 25 April 2013 - 08:39 PM

Thank for participating folks :) love you guys.
Was This Post Helpful? 0
  • +
  • -

#34 Blackish Wolf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-April 13

Re: The difference between Object objects and object reference?

Posted 27 April 2013 - 10:37 AM

Quote

It is used in Polymorphism!

Was This Post Helpful? 0
  • +
  • -

#35 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: The difference between Object objects and object reference?

Posted 28 April 2013 - 09:19 AM

Quote

It is used in Polymorphism!
I was thinking about that too, but as far as I can see, there really isn't much practical point to use polymorphism against an object from which all other objects derive. The essential characteristic of polymorphism is that it is a method of decoupling the structure of a class from its implementation. 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.

The Object class already has attributes and behaviors defined, and every class is an implementation of it. So, you could say that a consumer of the Object class could declare an object class and call its toString method in a context where it doesn't know whether it is calling an overridden method of toString or not, and you could say that that's polymorphism, but you're not bringing anything of value to the table by doing so. To create value with polymorphism, you need to define the interface you're going to polymorph as well as the implementations. Since everything is an object anyway, it's redundant to say that your reference is going to be an implementation of Object.
Was This Post Helpful? 0
  • +
  • -

#36 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 841
  • View blog
  • Posts: 2,576
  • Joined: 29-July 11

Re: The difference between Object objects and object reference?

Posted 28 April 2013 - 11:44 AM

View PostBobRodes, on 28 April 2013 - 04:19 PM, said:

The essential characteristic of polymorphism is that it is a method of decoupling the structure of a class from its implementation. 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.


I am just a self-taught n00b, but that sounds more like encapsulation to me.

This post has been edited by farrell2k: 28 April 2013 - 11:45 AM

Was This Post Helpful? 0
  • +
  • -

#37 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: The difference between Object objects and object reference?

Posted 28 April 2013 - 06:33 PM

most of the time polymorphism is encapsulation or it is kind of useless
Was This Post Helpful? 0
  • +
  • -

#38 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7747
  • View blog
  • Posts: 13,104
  • Joined: 19-March 11

Re: The difference between Object objects and object reference?

Posted 28 April 2013 - 08:58 PM

View Postpbl, on 28 April 2013 - 08:33 PM, said:

most of the time polymorphism is encapsulation or it is kind of useless


Not sure I follow you.

Polymorphism is a technique for allowing objects to share behavior, encapsulation is a tool for preventing objects from sharing data. You could get there by a sort of around-the-corner logic (both encapsulation and polymorphism feature strongly in the design of Java's object model) but if you look at Ruby or python you have plenty of support for polymorphism, but little or none for encapsulation, and people find both of those to be quite useful languages.
Was This Post Helpful? 0
  • +
  • -

#39 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7747
  • View blog
  • Posts: 13,104
  • Joined: 19-March 11

Re: The difference between Object objects and object reference?

Posted 28 April 2013 - 09:06 PM

View Postfarrell2k, on 28 April 2013 - 01:44 PM, said:

View PostBobRodes, on 28 April 2013 - 04:19 PM, said:

The essential characteristic of polymorphism is that it is a method of decoupling the structure of a class from its implementation. 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.


I am just a self-taught n00b, but that sounds more like encapsulation to me.


Not exactly. Encapsulation is the ability to wall off the data belonging to a particular domain of the problem, to reduce complexity. Polymorphism is many things, but one of the benefits it brings is the ability to use an abstract notion, for example a Map or a List, or indeed a Person, Place or Object, without knowing anything at all about how it is implemented.

By example, polymorphism is the ability to call toString() on any Object in java to get a representative String, while encapsulation is the ability to prevent any other class from directly accessing the String representing this Object except by calling the toString method.
Was This Post Helpful? 0
  • +
  • -

#40 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 841
  • View blog
  • Posts: 2,576
  • Joined: 29-July 11

Re: The difference between Object objects and object reference?

Posted 28 April 2013 - 10:40 PM

View Postjon.kiparsky, on 29 April 2013 - 04:06 AM, said:

Not exactly.


No. Pretty much exactly. Encapsulation really has nothing to do with Polymorphism. Defining attributes and behaviors as well as the interface of a class without having to share those details is 100% encapsulation, every day of the week.

I don't follow pbl either, but I have a feeling he's going to try to stretch the definitions of both polymorphism and encapsulation in an attempt to blur the lines between the two. :lol: That's OK. though. We all love big daddy!

This post has been edited by farrell2k: 28 April 2013 - 10:43 PM

Was This Post Helpful? 0
  • +
  • -

#41 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7747
  • View blog
  • Posts: 13,104
  • Joined: 19-March 11

Re: The difference between Object objects and object reference?

Posted 28 April 2013 - 11:45 PM

View Postfarrell2k, on 29 April 2013 - 12:40 AM, said:

View Postjon.kiparsky, on 29 April 2013 - 04:06 AM, said:

Not exactly.


No. Pretty much exactly. Encapsulation really has nothing to do with Polymorphism. Defining attributes and behaviors as well as the interface of a class without having to share those details is 100% encapsulation, every day of the week.


Hrm? Interfaces are exactly a tool for polymorphism. I can provide any number of Lists - ArrayLists and LinkedLists and ShoppingLists and LaundryLists, and if they implement the List interface, then they're Lists, and nobody calling them as Lists can care about their implementations. That's what polymorphism means.

So it's a little weird that you assert that polymorphism is "100% encapsulation, every day of the week" and in the same breath deny that the two concepts are related. Perhaps you should pick one position or the other, or some intermediate one. In normal usage, what Bob described is polymorphism, and not encapsulation.
Was This Post Helpful? 0
  • +
  • -

#42 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 841
  • View blog
  • Posts: 2,576
  • Joined: 29-July 11

Re: The difference between Object objects and object reference?

Posted 29 April 2013 - 05:43 AM

View Postjon.kiparsky, on 29 April 2013 - 06:45 AM, said:

View Postfarrell2k, on 29 April 2013 - 12:40 AM, said:

View Postjon.kiparsky, on 29 April 2013 - 04:06 AM, said:

Not exactly.


No. Pretty much exactly. Encapsulation really has nothing to do with Polymorphism. Defining attributes and behaviors as well as the interface of a class without having to share those details is 100% encapsulation, every day of the week.


Hrm? Interfaces are exactly a tool for polymorphism. I can provide any number of Lists - ArrayLists and LinkedLists and ShoppingLists and LaundryLists, and if they implement the List interface, then they're Lists, and nobody calling them as Lists can care about their implementations. That's what polymorphism means.

So it's a little weird that you assert that polymorphism is "100% encapsulation, every day of the week" and in the same breath deny that the two concepts are related.


This is a fine example of someone reading what they want to read, instead of what is actually written. :lol

A class's interface to the outside world. i.e. Which members are private/public, NOT Interface types inherited by a class. Encapsulation, every minute of the day, every day of the week! Nothing weird about it.

This post has been edited by farrell2k: 29 April 2013 - 05:55 AM

Was This Post Helpful? 0
  • +
  • -

#43 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7747
  • View blog
  • Posts: 13,104
  • Joined: 19-March 11

Re: The difference between Object objects and object reference?

Posted 29 April 2013 - 08:29 AM

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 is a relationship between classes: one type can be treated as another if it meets certain conditions, namely, it inherits certain behaviors from the other class. This is what Bob means when he talks about "decoupling the structure of a class from its implementation." That is, an object has certain behavior by contract, but the contract does not specify anything about how that behavior is to be implemented.

Encapsulation is the ability to protect class members from access by other objects.

These are not the same thing: encapsulation is a negative capacity, a capacity to deny access, and polymorphism is a positive capacity, a capacity to guarantee access.

Encapsulation decouples your classes by protecting their fields and methods: If class Foo can access class Bar's data, and vice versa, they are effectively one class, ie, they are "tightly coupled", and if I make changes to one, I have to debug both.

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 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.

And that's pretty much all there is to say about this. Two technical terms with well-defined meanings. As it happens, Bob used the term "polymorphism" correctly, to describe polymorphism, correctly. Now I have to get back to work. If you're still confused, please do some reading.
Was This Post Helpful? 1
  • +
  • -

#44 RozenKristal  Icon User is offline

  • D.I.C Regular

Reputation: 45
  • View blog
  • Posts: 343
  • Joined: 29-September 12

Re: The difference between Object objects and object reference?

Posted 29 April 2013 - 08:41 AM

Oh, this topic still going on. Nice guys, thank for going such length :D
Was This Post Helpful? 0
  • +
  • -

#45 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: The difference between Object objects and object reference?

Posted 29 April 2013 - 09:08 AM

What I was saying, or trying to say in that weird language that is English where you park or drive way but drive on parkway, is that if polymorphism allos you you perform the same operation different ways it means that you can't determine how it works inside and so it gives encapsulation the fact.

Sure that the fact that I can do
new FileOutputStream("filename"); or
new FileOuputStream(aFileObject);
let me guess that most probaly the first one simply does
this(new File(stringReceivedAsParam));

but in other cases it is quite less evident so the internal mechanisms are encapsulate

And if olive oil is made out of olives what baby oil made from ?
If snow balls are amde of snow what snow tires made from ?
Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4