4 ms·
In this case I would use something like std::function in C++. An std::function can also be unititialized and one can test for that using 'if'. Obviously, one do
by cjfd 7y ago
In this case I would use something like std::function in C++. An std::function can also be unititialized and one can test for that using 'if'. Obviously, one does not want an inheritance hierarchy as complicated as the one you sketch. It does seem like a dynamic language maps a bit more direct to this problem. However, if one uses a dynamic language there still is the complication that there is not a single place with a list of all possible attributes that the Animal can have. This is one main pain of dynamic objects that one especially feels when one is trying to find out how something works. When something can potentially be any type one might have to read a great amount of code to find out what operations are available for that thing.
I also have to notice that this is not a very typical problem. I don't seem to remember that I have ever had to model something like this in a programming language.