Interesting article on programming languages
Roey Katz
katz at glue.umd.edu
Wed Jan 26 19:01:16 EST 2000
The 'virtual classes' that Sweeney describes look to me an awful lot
like something like this:
class myClass:
def __init__( self ): pass
def doSomething( self ): print 'instantiating'
class myClass2:
def __init__( self ): pass
def doSomething( self ): print 'instantiating (2)'
class Base:
virtualClass = None
def __init__( self ):
self.inst = self.virtualClass()
self.inst.doSomething()
class Derived1( Base ):
virtualClass = myClass
class Derived2( Base ):
virtualClass = myClass2
-----------------
Isn't this the same thing? I noticed that the virtual classes in
Sweeney's code sample were all of the same base class; to
me, it seems that Python's object model is one of policy, not rules:
if an object responds to a message, so be it, regardless of what
*kind* of object it is -- so we have a little more freedom with
Python. Correct me if I'm redundant?
I enjoy these constructs because they allow me to design flexible
interfaces in the base class that I don't have to change at all as I
add new features (sounds coherent?) I'm using this for a role playing
game.
Roey
More information about the Python-list
mailing list