Today, one very simple question came to my mind when I had to override TObject
's BeforeConstruction
method:
Why do TObject
methods AfterConstruction
and BeforeConstruction
have public
visibility?
I expected them to be protected
.
What is the reason they aren't?
I can't imagine a valid purpose to call AfterConstruction
or BeforeConstruction
without calling the constructor or destructor of that class. Do you?
A previous question asked why some other methods are public instead of protected, and the answer was that they at some point needed to be called by utility functions that weren't attached to the class.
TObject.AfterConstruction
is called by just such a utility function, System._AfterConstruction
. If it were (strict) protected, then that standalone function wouldn't have access to the method.
All the methods of TObject
are public.* We can probably find rationales to explain why each method is public, but at a certain point, I suspect that the underlying reason for any given method being public is that all the others are, too.
Once Delphi was released with those methods public, any reduction in their visibility would have risked breaking existing code.
* Except for GetDisposed
and CheckDisposed
, for some reason. They're relatively new, compared to the bulk of TObject
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With