January 2020
Intermediate to advanced
532 pages
13h 31m
English
In mainstream object-oriented languages, we often implement getters for accessing the fields of an object. In Julia, we can also create getter functions. When implementing getter functions, we can choose which fields to expose as part of the application programming interface (API). For our example, we will implement getter functions for both fields, as follows:
get_heatmap(s::Simulation) = s.heatmapget_stats(s::Simulation) = s.stats
Our choice of function names here is somewhat non-idiomatic for the Julia language. A better convention is to use the nouns directly:
heatmap(s::Simulation) = s.heatmapstats(s::Simulation) = s.stats
So, when we read the code that uses the heatmap function, we can read it as the ...
Read now
Unlock full access