Object (computer science)

(Also called instance ) An object referred to in the object-oriented programming (OOP ) a copy of a particular data type or a particular class ( called " object type" ). Objects are concrete manifestations ( " instances" ) of an object type and during the term created ( instantiated ). You are assignment compatible not only to their own classes, but also to the corresponding base classes.

Pragmatic definition in C

In C there is a very pragmatic definition of what is considered there as an object:

Object region of data storage in the execution environment, the contents End of month can represent values Note: When referenced to object 'may be interpreted as having a Particular type; see 6.3.2.1

However, C is not an object-oriented programming language. The concepts of object-oriented software development, such as inheritance, polymorphism and encapsulation are missing in the core language and must be recreated via user-defined functions. For this purpose, there are various third-party libraries. Where is accessed only via these functions on an object, it meets the criteria of an object from OO perspective.

Properties

Each object has a state, behavior and identity. The state of the object consists of its properties together (attributes ) and links to other objects. The behavior of the object is described by the set of its methods. The identity of a different object from other objects, even if these other objects have the same state and the same behavior.

By construction ( see Constructors and destructors ) an object or item is created (instance) of a class. This instance has at runtime its own data type, properties and methods.

Instantiation

As an instantiation is called in object- oriented programming, producing a particular object of a particular class. During the instantiation of an object, a so-called constructor is executed in many programming languages.

The instance of a class is a concrete specimen with concrete forms, you can work with up to their destruction. For example, there could be ( for example, a shop software), a class " car " in a program that works with cars, is described in the abstract as possible, what properties a car. If in such a program a specific car, for example "Porsche, black, vehicle number X" is created, which is then available to the program for further use, we now call this an instance of the class " car ", and the process object creation is called instantiation.

Origin of the term instance

There is the assumption that today's parlance, " An object is an instance of a class" on an erroneous translation of the English term "instance " = "example", " occur " or "case" is based. The reason is the observation that instances in the legal context to each other always lie in an over -or under- child relationship. This assumption is, however, described by critics as false: = The Latin root " instantia " " Then the existence of " contains no such hierarchy of instances with each other. Rather instances must exist on other things, copies of which classes do ( they insist on classes or, more precisely, they are programming at runtime from a class generated ). Goethe also used the term " instance" already in the meaning of " copy ": " An instance of the animal kingdom the lowest level we still lead to more manual before here. "

Example

The source code for the object type ( class ) " book" with the identifying characteristic " inventory number" (in the case of a library and as a single instance ) contains the associated properties (inventory number, loan status, acquisition date, ...) and the description of how to edit the properties ( methods, such as the change in loan status in the event of a loan by a customer ).

An object is then a real expression of the class, so a particular book, such as with the inventory number 4711th Object-oriented programming languages ​​allow the simultaneous coexistence of different objects, so a book with the number 4711 and 1234.

Programming in C

The state of an object (in the sense of the above definition) is completely determined by the values ​​of its attributes. Unnamed attributes as well as padding bits and bytes ( Padding ) contribute nothing of the defined state of the object at, its content is undefined.

C has no methods. These must be functions that get a pointer to the object as the first parameter, simulated. Polymorphism is function pointers that are stored as attributes of the object can be realized.

The unique identity of the object is defined by its address. Thus, each object must have a unique address. This is ensured by providing each data structure has at least 1 byte of storage. If the address of an object in the program but not required, and the compiler can detect this, it is possible that this object not allocate memory because the semantics of the program is thus not change.

Difference between entity and object

The term "object" is used in the programming with the term "entity ". The terms entity ( styp ) and object (type) apply in their respective worlds, the world of data modeling and the world of object-oriented programming. They correspond to each other, but are not identical to or interchangeably. Thus, for example, a series object it 's own functions, properties, and methods, which is not the case with an entity. In other words, object type = program representation of the entity type plus corresponding processing functions (methods ).

612923
de