In programming, what is an object?

Asked

Viewed 3,586 times

26

In programming, it is common to hear the term objeto, often defined in multiple vague definitions, if defined.

What is, in fact, an object in programming (not limited to object-oriented programming)?

Show 4 more comments

3 answers

23


A physical object is a portion of atoms. It is something physical (Dãã). Of course in programming we deal with abstractions. What would atoms be to us developers? The bit, right? The smallest piece of information that the computer understands and is indivisible.

Then a set of bits ends up forming an object if they are arranged in a specific quantity and order set. In theory an object could even be a bit, but in practice to form a useful object we actually need at least 1 byte, possibly a set of them, even many of them, to form something that we can specifically identify. Obviously objects can be formed by a set of other objects.

The object there is the data, the information. It doesn’t matter what or where it is. It can even be an instruction, a code. Can be an integer value, a character, a text, a array, any data structure, can be what composes a dictionary, or a client in memory, in file, in the database.

One variable in programming is a name we give to a value, or we can say that it is a name we give to an object. For ease, it is common to treat the variable as if it were the object. In a certain way the variable is an object too, but it’s another object, it’s a box that contains the object that really matters (it’s just a storage location).

Strictly speaking what was said by the teacher is wrong, but it is fully acceptable to do this simplification of saying that the variable is the object, everyone does it. It is common to use almost synonyms to enrich language and simplify communication. Objects have identity. A variable does not.

Note that there are objects that the only information is a pointer to where another object is that is what really matters to that variable. They are the objects by reference. If there is the pointer in one place and the value that interests in another, they are two objects.

Object in this context is used for something generic. In mathematics we see this happening in a similar way.

Object orientation is to place the object as the center of development. Some people think the term is only used in this paradigm. In OOP the term has definitions a little more specific, but it is the same object of other languages, only changes the general organization of the code that generates and manipulates it.

In the question Why use pointers as function parameters? I use the term object all the time in a language that is not object oriented. Everyone uses that term in C all the time.

In other contexts the term may be something totally different.

an integer type variable, is an object?

The whole is an object. In a way the variable is still a secondary object, it is where this integer is stored, but what matters is the integer. But to say that the variable is an entire object is well accepted and is understandable.

  • 8

    I believe that the confusion of Vinicius occurs when one takes into account the language vices. Type, it is common as antagonistic objects and primitive. This antagonism makes sense when one takes into account the reduced contextualized meaning of the word object.

  • 1

    @Jeffersonquesado exactly that.

  • It cleared me well on object. Only in a part that "I believe I understood", but, there is that doubt of "I understood correctly!?" in: "Objects have identity. A variable does not.".

  • @Rbz if you don’t have it on the site I think it’s worth asking :) What I said there is just to not think that the variable is an object.

4

Adding to Maniero’s magnificent response.

From past context, I believe you are dealing with an object-oriented language with access to primitive types such as Java and C#.

An object in an abstract world is usually defined as a set of interactions with the environment and, to know how these interactions occur, need to have internal state. Wikipedia object-based language article defines an object as a set of operations and states. In this sense, a primitive type carries with it a value, therefore it is an object.

In languages like Java, it is said that something is an object if it is an instance of a class (or a array). Vide Java language specification, chapter 4. Now, due to the constraint of the context we are dealing with, a primitive cannot be an object, for it simply is, not an instance of someone.

Taking advantage and deepening a little for Java:

  • interfaces are promises of behavior, so they only provide methods; duck-typing languages do not require this, but statically-checked languages can make this very advantageous;
  • classes are a collection of behaviors and attributes;
  • classes can use another class to define themselves, this so-called inheritance process;
  • a class can implement an interface, so it promises that its objects have the behavior promised by the interface;
  • a class can delegate the implementation of a method to the next moment, as if it promised a behavior but did not implement it; these classes are called abstract;
  • a class does not need to have a name, it is an anonymous class; this is a common situation when you need to place an object that has a promised behavior in an interface, but the programmer found it unnecessary to create a class just like this;
  • and, to confuse everything, classes are objects; and they are objects of the class Class.
  • I took a closer look at the answer and corrected some mistakes that I had never seen you do :P (which I do a lot :D) I don’t know why I didn’t talk before, but go now. I have been sifting through my answers on primitives to make it clearer. https://answall.com/search?q=user%3A101+primitives. One of the things I talk about is that primitive is a simplification of the term. It’s an adjective, so the full term is primitive object, which reinforces what you commented on in my reply. I don’t like this idea of object-oriented language, it doesn’t exist...

  • ...there is language that allows and even encourages this. Object in any language can have behavior, the difference is that some force it to be with it in some or all cases (thankfully none of success requires it to be all). In my answers I’m reinforcing that this Java thing about saying that their definition of what is an object is that screwed with people’s heads, is a wrong definition, and it talks a lot about language. I quote her herself to show how bad it is to define wrong. She gave the idea that primitive is.

  • as opposed to object, which is not, and now that they will have objects that are neither primitive nor created by classes, what is it then? They’ll have to juggle or pretend they never said anything stupid and let it go.

1

I translate and comment here the definitions of Wikipedia in English, with a point to improve in the definition referring to object orientation.

In computer science, an object can be a variable, a data structure, a function, or a method, and as such, is a memory value referenced by an identifier.

Corresponds to the definition given by the accepted answer.

In class-based and object-oriented paradigms, an object refers to a particular instance of a class, where the object can be a combination of variables, functions, and data structures.

Here is a clarification. The definition is not wrong, but most often objects are better defined as being computational entities that unite state and operations acting upon that state. [1] [2]

At least when these two components change together. [3]

You can build an object in other ways in programming languages, but the general principle that guides the creation of an object (encapsulation) is to join data and operations related to that data.

Encapsulation is the act of uniting (co-locating) these two components into one object. [4]

Some places confuse casting with withholding information, but they are not the same [5].

Objects can also be defined as instances of a class, and class as the mold from which objects are made, but this is a little redundant.

In the relational database management model, an object can be a table or column, or an association between data and a database entity (such as relating a person’s age to a specific person).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.