The most common behaviour is to call inherited
. So if I explicitly do not want the inherited behaviour, I do not call inherited
. Otherwise, I do. If the inherited behaviour is a no-op like TObject.Create/Destroy
, I still call inherited
.
Note also that the situtation for constructors and destructors is perhaps a little different than for other methods. It's exceptionally rare that you would need to skip a call to the inherited method. I cannot think of an example. Invariably constructors are creating and destroying other objects, so how could you contemplate skipping that?
I know that some authors write code that omits inherited
when deriving directly from TObject
, because they know that the implementation in TObject
does nothing. I do not like that and to me it is a mistake to do that. The implementation details of TObject
should not be leaking into derived classes.
I'm pretty sure that TObject.Create/Destroy
will always be no-ops. If Embarcadero changed that then so much code would break. But what about one of your classes. Suppose you have a class derived from TObject
. And then you have another class derived from that:
TMyClass1 = class
....
end;
TMyClass2 = class(TMyClass)
....
end;
You have no constructor for TMyClass1
and a constructor for TMyClass2
that looks like this:
constructor TMyClass2.Create;
begin
// no need to call inherited, it's a no-op
FMyObj := TBlahBlah.Create;
end;
Then one day you modify the TMyClass1
constructor to do something. Now TClass2
is broken. So, I would never ever omit a call to inherited
because that call does nothing.
The situation for normal instance methods is a little different. It is more plausible that you want to ignore the base class implementation and provide a brand new implementation. But take the decision based on what the derived class wants to do rather than whether or not the super class has an empty implementation for the method.