Need help subclassing Borg

wittempj@hotmail.com martin.witte at gmail.com
Sat May 7 11:35:21 EDT 2005


See mr Martellis comment of 2001/09/06 in mentiond recipe, you then get
something like this

-#!/usr/bin/env python
-class Borg(object):
-    _shared_state = {}
-    def __init__(self):
-        self.__dict__ = self._shared_state
-
-class Duck(Borg):
-    def __init__(self):
-        super(Duck, self).__init__()
-        self.__covering = "feathers" # all ducks are feathered
-    def covering(self):
-        return self.__covering
-
-class Rabbit(Borg):
-    def __init__(self):
-        super(Rabbit, self).__init__()
-        self.__covering = "fur" # all rabbits are furry
-    def covering(self):
-        return self.__covering
-
-bugs = Rabbit()
-daffy = Duck()
-print daffy.covering()
-print bugs.covering()

martin at ubuntu:~$ ./test2.py
feathers
fur
martin at ubuntu:~$




More information about the Python-list mailing list