The instance is an object and the object is an instance? Then would the
same thing?
Yes and no.
On the Wikipedia page itself there are 3 paragraphs that speak the same thing in different ways. It is redundant but they did so to clarify better.
Instances of a class share the same set of
attributes, although they differ as to the content of those
attributes. For example, the "Employee" class describes the attributes
common to all instances of the "Employee" class. The objects of this
class may be similar, but vary in attributes such as "name"
and "salary". The class description contains the items corresponding to
those attributes and defines the operations or actions relevant to the
class such as "salary increase" or "change in the number of
phone". One can then talk about an instance with the name = "Joana
Rabbit" and another with the name = "João Coelho".
Instance is the embodiment of a class. Intuitively, a
class is like a "mold" that generates instances of a certain type; a
object is something that exists physically and has been "shaped" in the class.
Thus, in object-oriented programming, the word "instantiation"
means to create. When we speak of "instantiating an object", we create
physically a concrete representation of the class. For example:
"animal" is a class or a mold; "dog" is an instance of
"animal" and despite carrying all the mold characteristics of
"animal" is completely independent from other instances of
"animal"
https://pt.wikipedia.org/wiki/Inst%C3%A2ncia_(class)
// Aqui temos uma classe. Ela ainda não é um objeto.
Class Foo{}
// Aqui criamos um objeto da classe Foo
obj = new Foo
// Repare que não usei o termo "instância" porque esse termo significa "criar". Contudo, não é errado dizer:
// Nova instância de Foo
obj = new Foo
That is, the obj
is a objeto
instantiated from the class Foo
.
Instance (instantiating/creating) is an action. The object is a concrete representation, according to wikipedia, we create (instantiation) physically a class representation.
The definition of what the object is also very clear and I see no ambiguity:
In computer science, object is a reference to a
memory that has a value. An object can be a variable, function,
or data structure. With the introduction of
objects, the word object refers to an instance of a class.
In object-oriented programming, an object comes into existence from
of a "mold" (class); the class defines the behavior of the object,
using attributes (properties) and methods (actions).
https://en.wikipedia.org/wiki/Object_(computer_science)
Important to note that still on the Wikipedia page brings an observation on the term instance.
In object-oriented programming, it’s called a class instance,
an object whose behavior and state are defined by the class.
"Instance" is, in this case, a anglicism, meaning "case" or
"example" (in English instance).
Anglicism: https://en.wikipedia.org/wiki/Anglicism
Not to complicate matters, I’ll avoid commenting on Metaclass because it escapes a little from the context of the question. But anyway it is good to know.
The theme is covered in the Japanese version of "Instance": https://ja.wikipedia.org/wiki/%E3%82%A4%E3%83%B3%E3%82%B9%E3%82%BF%E3%83%B3%E3%82%B9
静的型付けのオブジェクト指向言語では珍しいが、動的型付けのオブジェクト指向言語の多くは、メタクラスをサポートし、クラス自体もオブジェクトとして扱うことができる(クラス・オブジェクト)。 クラス・オブジェクトは、端的に言えば変数に束縛できるクラスである。 クラス・オブジェクト、インスタンス・オブジェクト双方を変数に束縛した際どちらもオブジェクトとして振る舞い見かけ上区別はつかない。 例えばクラス・オブジェクト、インスタンス・オブジェクト双方が
readFrom: というメソッドを持っていた場合、どちらも #readFrom:
メッセージを送ってやるとエラーも起こさずそれぞれのメソッドを実行する。
Objective-CやPythonにおいてはクラス・オブジェクトとインスタンス・オブジェクトの明確な区別が行われている。 [3][4]
メタクラスがサポートされているシステムでは、クラス・オブジェクトもまた別のクラス(メタクラス)のインスタンスであるということがありうる。 この場合「クラス・オブジェクトはインスタンスではない」とは言えないので、注意されたい。
This is a brief warning that says not to confuse instances of metaclasses because in metaclasses instances are also classes.
As you can see, we can always complicate even more.
An individual Object of a Certain class = 1 single item of a class... if I have a group of people... the object is people... and the instance is Daniel... Anderson... Joao... instance is 1 unique created object of the class... if I have 10 feet of lime ... the object is the lemon foot, and each lime foot is an instance of the lemon foot type Not that they are equal, object refers as the whole and instance is specifically where that class, that object appears... basic example would look like this: Model model; Model = object and model = instance of the Model class
– Daniel Gentil
In programming, or in programs, it would look something like this: Object -> characterizing properties. Instance -> Existence, or even the materialized form. Color of a Car, Engine Type, Number of Wheels would be basically the object itself, and "A Car" would be an instance of that object.
– Edilson
In this phrase that the PA cited did not understand where is the difference between the two: "The object is an instance of the class and the instance accesses the predefined behaviors". If an object is an instance as the phrase states, one can substitute instance for object and so is "the object accesses the predefined behaviors". No differentiation here.
– Piovezan