January 2020
Intermediate to advanced
532 pages
13h 31m
English
For mutable types, we may implement setters. The scope would include fields that can only ever be mutated. For our simulation project, suppose that we want to allow the client program to do some transformation of the heatmap and put it back to the object. We can support that use case easily, as shown in the following code snippet:
function heatmap!( s::Simulation{N}, new_heatmap::AbstractArray{Float64, N}) where {N} s.heatmap = new_heatmap s.stats = (mean = mean(new_heatmap), std = std(new_heatmap)) return nothingend
The setter function, heatmap!, accepts a Simulation object and a new heatmap array. Because the stats field contains the statistics of the underlying heatmap, we must maintain consistency within ...
Read now
Unlock full access