Waldek Hebisch wrote:
Frank Heckenbach wrote:
Markus Gerwinski wrote:
Frank Heckenbach wrote:
BP seems to allow overriding a public method with a private one (and vice versa). Does this seem reasonable?
Only if the privacy degree of the overriding method is _lower_ than that of the the overridden one. E.g. the following declaration would make sense due to the principles of OO programming:
type
a = object protected procedure p; virtual; end; b = object (a) public procedure p; virtual; end;
The other way around -- making a method "more private" -- would contradict the principle of polymorphy.
I agree. (markus9.pas)
Both ways make some sense. "Normal" way is to extend the interface (so making a method public looks more natural). However, to support encapsulation one may create a "view", where only some method are visible. BP may be misguided here, but ability to make method private sometimes may do as substitute for views. Limiting visibility have nothing to do with polymorphy -- the method still have to be in VMT, but may called only where static type (= interface) allows.
But such a "view" could easily be bypassed by passing the object (polymorphically) to a formal parameter of the parent type, so I don't see what it gains, apart from confusion. Or actually worse, since you'd allow a private method to be called from outside (without dirty tricks, just through the VMT in a "public" place).
Frank