Interface Implementation in Python

MonkeeSage MonkeeSage at gmail.com
Tue Mar 6 19:58:09 EST 2007


On Mar 6, 6:23 pm, p_sha... at yahoo.com wrote:
> I dont want to expose the above Point3D implementation to the user /
> client side.To achieve that we can use interface concept.In Python to
> use interface concept.

In python you would use name mangling to hide parts of the interface
from the public.

class Point3D:
    def __init__(self):
        self.__x = 0.0
        self.__y = 0.0
        self.__z = 0.0

    def __setPoint(x,y,z):
        self.__x = x
        self.__y = y
        self.__z = z

    def __getPoint(x,y,z):
        x = self.__x
        y = self.__y
        z = self.__z

p = Point3D()
p.__setPoint(1,2,3)

# ...
# AttributeError: Point3D instance has no attribute '__setPoint'

Regards,
Jordan




More information about the Python-list mailing list