Creating mutable classes
So far, we have worked with different types of properties. When we declare stored instance properties with the
var keyword, we create a mutable instance property, which means that we can change their values for each new instance we create. When we create an instance of a class that defines many public-stored properties, we create a mutable object, which is an object that can change its state.
A mutable object is also known as a mutating object.
For example, let's think about a class named
MutableVector3D that represents a mutable 3D vector with three public-stored properties:
z. We can create a new
MutableVector3D instance and initialize the
z attributes. Then, we can call the
sum method with the delta ...