Frank Heckenbach wrote:
Waldek Hebisch wrote:
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).
The same is true for real views (or restricted types). The point is that any code which is allowed to know parent type is allowed to call the method -- you restrict access to the method by restricting access to the parent. In EP modules you may export only child, so only dirty tricks will get you at the parent. And even if not strictly enforced making method provate still serves as documentation and catches some mistakes. In short -- I think that there are good reasons to turn public method into privete method. If (when) we implement Object Pascal views we will have better apporach, but it still may be good idea to remain BP compatible.