January 2020
Intermediate to advanced
532 pages
13h 31m
English
The reason to have a hierarchy is to create an abstraction about common behaviors for types. For example, the Apartment and House types have the same supertype, Property. This is intentional because they both represent some kind of physical dwelling at a certain location. So, we can define a function for any Property as follows:
""" location(p::Property) Returns the location of the property as a tuple of (latitude, longitude)."""location(p::Property) = error("Location is not defined in the concrete type")
You may ask, What have we done? We have just implemented a function that does nothing but return an error! Well, believe it or not, defining this function actually serves several purposes:
Read now
Unlock full access