January 2020
Intermediate to advanced
532 pages
13h 31m
English
It is also useful to define interactions between abstract types. Now that we know that every Property should have a location, we can define a function that calculates the walking distance between any two properties, as follows:
function walking_disance(p1::Property, p2::Property) loc1 = location(p1) loc2 = location(p2) return abs(loc1.x - loc2.x) + abs(loc1.y - loc2.y)end
The logic completely lives in the abstract types! We have not even defined any concrete types, and yet we are able to develop generic code that works for any concrete subtypes of Property going forward.
The power of the Julia language allows us to define these behaviors at this level of abstraction. For a moment, let's imagine what we would have ...
Read now
Unlock full access