Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between stateless and immutable?

Tags:

People also ask

What is an example of immutable?

An example of immutable is something that has happened and cannot be reversed. Unable to be changed without exception. The government has enacted an immutable law. (programming, of a variable) Not able to be altered in the memory after its value is set initially, such as a constant.

What is mutable and immutable difference?

If the value can change, the object is called mutable, while if the value cannot change, the object is called immutable.

What is a stateless object?

A stateless object saves no application data; it is idempotent. Each operation on the object is independent of any other operations.

What is the difference between mutable and immutable types give example?

To summarise the difference, mutable objects can change their state or contents and immutable objects can't change their state or content. Immutable Objects : These are of in-built types like int, float, bool, string, unicode, tuple. In simple words, an immutable object can't be changed after it is created.


I often hear the term "Stateless" and "Immutable". For example, HTTP is a stateless protocol, and a String object is an immutable object. But I have a hard time grasping the difference between the two. When I create a stateless object, it doesn't store any "state" data internally. And if I create an Immutable object, it mean its will never change.

  • http://en.wikipedia.org/wiki/State_(computer_science)
  • http://en.wikipedia.org/wiki/Immutable_object

Doesn't that mean the same thing?

Since the immutable object doesn't change, by definition it cannot have a state. It is what it is forever. And if an object doesn't have state, it cannot be mutated (by definition). Thus, aren't all stateless object immutable and immutable object stateless?

What could be an example of mutable stateless object or immutable stateful object?