January 2020
Intermediate to advanced
532 pages
13h 31m
English
Although it does not sound very interesting, we can define functions that are solely based on the type itself:
# simple functions on abstract typesdescribe(a::Asset) = "Something valuable"describe(e::Investment) = "Financial investment"describe(e::Property) = "Physical property"
Now, if we ever call describe with a data element that has a supertype of Property, then the description method for Property will be invoked accordingly. As we did not define any description function with the Cash type, when describe is called with a Cash data element it will return the description from the higher-level type, Asset.
Read now
Unlock full access