Main Page | See live article | Alphabetical index

Object creation

In computer science, object creation, also known as instantiation, is the process of creating objects in object-oriented programming. It marks the onset of lifetime of an object.

In OOP, the meaning of creating objects is far more subtle than simple allocating of spaces for variables. First it is due to that in OOP, the lifetime of each object tends to vary more widely than in the case in conventional programming. There are a lot of subtle questions such as should the object considered alive in the process of creation or about the order of calling initializing code. In some sense, the creation can happen before the beginning of the program when objects are placed in a global scope.

In a typical case, the process follows:

Those tasks can be completed at once but are sometimes left unfinished and the order of the tasks can vary and can cause several strange behaviors. For example, in multi-inheritance, which initializing code should be called first is a difficult question to answer.

It is a complex problem how to create each object as element of an array. Most languages leave this to programmers.