Close access to the base class public methods

Steve Holden steve at holdenweb.com
Tue Nov 11 13:12:52 EST 2008


RinKaMeAri wrote:
> Hi!
> Could you imagine any way to block access to the base class public
> methods?
> Here is an example:
> class B:
>     def public_method():
>         pass
> 
> class A(B):
>     def public_a_method():
>          pass
> 
> def a = A()
> 
> Is there any way to block the call a.public_method() without any
> changes to B class?
> Thank you!

The simplest way would be to override B.public_method within A by
defining A.public_method to raise a NotImplementedError or similar
exception. Though of course this then begs the question of why A would
need to subclass B in the first place, but I assume there would be
methods you *did* want to implement.

Perhaps more background would yield a better solution.

regards
 Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list