Superclass' methods in Module

@Vortico, you mentioned on several topics that its OOP’s contract to call a superclass’ method if overriding. Can you explain why we don’t need to follow this pattern in Module's dataToJson or dataFromJson?

Well, the superclass functions don’t do anything, so there’s no need to. I guess it could be considered a style thing… It’s even difficult to imagine what the superclass even could be doing here, if they did anything, since the JSON in question is entirely your own.

Yes, they don’t do anything right now, but they might in a future version. I know that parameters are handled somewhere else, but saving their values could be done in Module::dataToJson. So, I can imagine something that could be there :wink:

Module::dataToJson/dataFromJson will always have placeholder implementations, so there is no need to call the superclass method. You could call them if you want, but it will be always be useless code.

In doubt I always check any method I override by looking at API source code. And forgetting to call the superclass happen so often that I guess it’s good pratice even if it ends up calling a placeholder code block.

I should also note that the “method overriding contract” is actually: Always call the super method by default. Not calling it should be a conscious decision, not the default.

Thanks for clarifying!

In the API the returns a json object, the superclass returns null. It’s difficult to imagine how one would correcty call that api from a derived class.

json* myCLass::dataToJson() {
    json* ret = Superclass::dataToJson();
    assert(!ret);
    ret = myOwnSerializationCode();
    return ret;
}

The issue of course is that there is nothing sensible to do with the value returned from the superclass.