Stateless vs Stateful classes in C# #179
-
Dear Nagel, On page 486, you mentioned Stateless and Stateful classes, but you didn't explain these classes in your book. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
With a stateful class you can set and change state, e.g. a Person class with a FirstName property with get and set accessor. The values can change. With a stateless type you can't change the state. In case multiple threads access the same stateful object instance, you need to synchronize the access from threads, otherwise you can get race conditions. If you use an object that can't change the state and access it from multiple threads, you will have less issues. |
Beta Was this translation helpful? Give feedback.
With a stateful class you can set and change state, e.g. a Person class with a FirstName property with get and set accessor. The values can change.
With a stateless type you can't change the state.
In case multiple threads access the same stateful object instance, you need to synchronize the access from threads, otherwise you can get race conditions.
If you use an object that can't change the state and access it from multiple threads, you will have less issues.