April 2017
Intermediate to advanced
316 pages
9h 33m
English
Immutable objects are useful in multi-threaded applications because multiple threads can act on the data of immutable objects without worrying about changes to the data by other threads.
As immutable objects are closed to change, it is safe to assume that they will stay unchanged while we access the object from different threads. This assumption simplifies most of the multithreading problems that are complex to solve and maintain. For instance, we do not need to think about synchronization/locking mechanisms at all.
Suppose that we have a mutable object that includes a mutable array of a type, for example, a Product class that has four properties:
struct Producer { let name: String let address: String } class Product { Read now
Unlock full access