In programming, what is an object?

14

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)?

    
asked by anonymous 17.05.2017 / 22:22

2 answers

17

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

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

The object there is the data, the information. It does not matter what or where it is. It may even be an instruction, a code. It can be an integer value, a character, a text, an array, any data structure, can be what makes up a dictionary, or a client in memory, in file, in the database.

A variable in programming is a name that we give to a value, or we can say that it is a name that 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 as well, but it is another object, it is 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 make 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 is not.

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

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

The 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 somewhat more specific definitions, but it is the same object of other languages, it 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 one language that is not object-oriented. Everyone uses this term in C all the time.

In other contexts the term may be something entirely different.

  

a variable of integer type, is an object?

The integer is an object. 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 integer object is well accepted and understandable.

    
17.05.2017 / 22:42
4

Adding to Bigown's magnificent answer .

From the 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 must have an internal state. Article about object-based languages from Wikipedia defines an object as a set of operations and states. In this sense, a primitive type carries with it a value, so 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 an array). See java language specification, chapter 4 . Now, because of the constraint of the context of which we are dealing, a primitive can not be an object, for it simply is not an instance of someone.

Leveraging and deepening a bit for java:

  • interfaces are promises of behavior, which is why they only provide methods; languages with duck typing do not need 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, process this called inheritance;
  • A class can implement an interface, so it promises its objects to have the behavior promised by the interface;
  • A class can delegate the implementation of a method to a next time, as if it promises a behavior but does not implement it; these classes are called abstract;
  • A class need not have a name, it is an anonymous class; this situation is common when you need to put an object that has a promised behavior in an interface, but the programmer found it unnecessary to create a class with only that
  • and to confuse everything, classes are objects; and are objects of class Class .
18.05.2017 / 04:30