Frage

Wikipedia defines an object as "a location in memory having a value and possibly referenced by an identifier."

But "object" also seems to be a language construct. For example, MDN defines a JavaScript object as "a collection of properties, and a property is an association between a name and a value."

I guess what I'm asking is this: is there any relationship between the language construct of an object and an object as a contiguous block of memory? I had thought there wasn't, but in the Coursera compilers course I am taking, the professor seems to be making a one-to-one relationship between the class structure in a program and the actual layout of that data in memory. And now that I think about it, it would make sense that JavaScript objects are laid out in a similar manner, although inheritance would be different.

War es hilfreich?

Lösung

Object is very generic term in software development. It's not only that object have different definitions, but also it can refer to different concepts.

Maybe the "default" meaning (at least in OO theory) would be, that object is a run-time instance of a defined class (please refer to some OO book for more details).

Even in this case the meaning is not free of ambiguity, as classes and objects can exist on several levels of abstraction. Two extrems are conceptual classes (and objects) and implementation classes (an objects).

In the second case, you can definitelly say that object also is "location in memory" (on the lowest possible physical level) and "language construct" (on a coding level). On the conceptual level, physical memory does not make sense (no executing program), so no "location in memory", while "UML language construct" could be acceptable. :)

Javascript objects do not require classes to exist, so they are not object in that sense. They are JS language constructs and during the run-time also "locations in memory".

Sometimes, informal conversation, it can go even farther away - Json objects, XML objects, etc. It obviously does not have anything to do with OO and I would say that "object" can be replaced with something neutral like "element".

For all mentioned types of objects, it could be also said that they are "a collection of properties, and a property is an association between a name and a value."

So, all the definition you mentioned are true. In order to agree on the one, we should first set the concrete context.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top