Behaviour

Value types do not behave. A value type stores data and provides methods to use its data. A value type can only have a single owner and it does not have deinitializers as there are no references involved. Some of the value type methods may cause the value type to mutate itself, but control flow is rigidly controlled by the single owner of the instance. As the code will only execute when directly invoked by a single owner and not from many sources, it is easy to reason about the value type code execution flow.

On the other hand, a reference type might subscribe itself as a target of other systems. It might receive notifications from other systems. These sorts of interactions require reference types as they can have multiple owners. It's unnecessarily difficult to develop value types that perform side effects on their own in most cases.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset