# Definition of the state of an object in OOP

I need a concise definition of the "state of an object" in object-oriented programming (for a paper).

For about half of a day I searched for a paper that I can cite on this topic, but I couldn't find one. All the papers I found were mostly general papers on object-oriented programming and they didn't define the state of an object.

I am unsure, but my best guess is something like: The state of an object is defined by the state of the instance variables of the object.

I am searching for a definition of the state of an object and/or a reference on the topic.

(btw, could I refer to the concept as "object state" or is this uncommon?)

• I think there is room for ambiguity here, so that you should have stated in your paper exactly what _you _ meant by ‘state’; if you could not do that, perhaps you were not in a position to release your paper. – PJTraill May 6 '19 at 12:32

You can take a look to (and cite) the book "Object-Oriented Analysis and Design" by G. Booch:

... An object is an entity that has state, behavior, and identity. The structure and behavior of similar objects are defined in their common class. The terms instance and object are interchangeable.

We will consider the concepts of state, behavior, and identity in more detail in the sections that follow. ...

And there is a whole subsection that describes the concept of state:

... From this example, we may form the following low-level definition.

The state of an object encompasses all of the (usually static) properties of the object plus the current (usually dynamic) values of each of these properties ...

• Fuzzy, as usual. What Booth probably meant to say: a state is an assignment of values to those variables. – reinierpost Feb 24 '18 at 23:35

You would also want to keep in mind that the state of an object is an "abstract" entity, as determined by what is observable by the methods. For instance, an object that implements a hash table has as its state, the collection of values stored in the hash table, not all the internal representation details.

IBM has a glossary that defines the word "state" in several different definitions that are very similar to one another. They don't specifically state that they are related to Object Oriented Programming but one can extrapolate and use them in that context.

Def 3: A stage in the lifecycle of an object that identifies the status of that object.

Def 5: A condition or situation during the life of an object during which it satisfies some condition, performs some activity, or waits for some event.

Def 8: An object's characteristic that is manifested in its public and private data members, and can be divided into two categories: essential state and non-essential state.

Def 9: In a business state machine, one of several discrete individual stages that are organized in sequence to compose a business transaction.

Def 10: A condition in which the circuit remains until application of a suitable pulse.

Webster's New World College Dictionary defines 'state' as:

A set of circumstances or attributes characterizing a person or thing at a given time; way or form of being: condition

The common denominator of all these is time. State changes as time progresses. That is the nature of variables. If someone were to ask, "What is your current state?" You could say today that you are married and tomorrow you could be single.

Considering all these definitions one can extrapolate that 'state' is the way that an object exists at a particular point in time determined by the values of its attributes, namely it's properties/variables.

I don't think it gets any simpler than that.

• This is worth a few votes, as it makes the potential for ambiguity clearer than the other answers. – PJTraill May 6 '19 at 12:27
• Re my previous comment: I have since added an answer of my own to describe the ambiguity more thouroughly. – PJTraill May 12 '19 at 10:05

The term ‘state’ may be used in various senses, which may not even all be susceptible of a precise definition. It was therefore important that you include a definition in your paper, to make quite clear how you were using the term. In the following I do not offer a unique definition of the state of an object but rather try to sketch a number of ways of thinking about it, which may be appropriate in different contexts.

First, however, you need to think what you mean by ‘object’: are you thinking about a conceptual object, i.e. some entity you are trying to model, or about an instance of a class in a specific programme; perhaps you also want to think about the state of a variable which could at different times refer to different objects or about a system, maybe as accessed via a certain user interface.

Part of the difficulty in defining the state of an object in OOP is that when we model entities in a particular language, that language often does not permit us to distinguish object attributes which are conceptually part of the same entity from others that are not. For example, a linked list of Car will consist of a number of Link-objects, which contain pointers to the next (and maybe previous) Link although conceptually the list is a single object; the links may also be embedded in Car-objects or contain pointers to them, but in this case the linked objects are conceptually separate rather than part of the list; in a list of recent changes, hoewever, the changes may only be present in the list and considered as part of it. In these various cases we must decide whether we consider the state of one object to include that of the linked objects. Further, a Car may have a link to an Registering_Authority – we probably do not consider the state of car to change when its registering authority changes the URL of its website. Unless the implementation language does allow us to distinguish different types of link, it will not be possible make a general definition of the state of an object in terms of the language alone.

The ‘external’ or ‘functionalstate could be defined as ‘how it behaves’, ee.g. how it reacts to method invocations or to a user interface. For an object as a class instance this definition depends on the type to which the object is seen as belonging: seen as a Circle, the colour of a Coloured_Circle is not visible, and hence irrelevant to its state. A difficulty with this is that ‘how it reacts’ may need to defined in terms of values returned, and these ‘values’ might be the states of other objects. One way to formalise this is to say that two states of an object are the same if all possible future executions of some system in which it is embedded result in the same mapping from inputs to that system to outputs from it. This enclosing system may be required to be a self-contained system, capable of execution independent of its environment; on the other hand, one could allow it to be as small as the object in question itself. In any case, a mathematical approach is then to define a state as an equivalence class of

The ‘internalstate could be defined as the state of the representation. A first attempt is apparently circular but perhaps helpful: ‘The internal state of an object is the state of its members’. Here we need to take care to distinguish significant aspects of the representation from insignificant ones: at the lowest level, the representation of an object may well include addresses of other objects, but it is unlikely to be useful to consider a change in such an address as a change in state. On the other hand, a change in the state of a cache for the result of a query, while it makes no difference to the functional state (as described above), will be important when considering performance tests.

An object-oriented system integrates the terms of code and data using the concept of an "object". An object has state (data) and behavior (code). Hence, the states of object are the instances(variables) inside the object that contains the data.

• This is true but it doesn't sseem to add a lot to the existing answers. – David Richerby Dec 31 '14 at 18:30
• Maybe It'll be easy to understand for someone :) – Syed MEhran Hussain Dec 31 '14 at 18:57
• This is wrong. What you mean to say, I think: a state is an assignment of values to those variables. – reinierpost Feb 24 '18 at 23:33