Prothon Prototypes vs Python Classes

has has.temp2 at virgin.net
Wed Mar 31 16:24:35 EST 2004


Joe Mason <joe at notcharles.ca> wrote in message news:<slrnc6e2sm.fhj.joe at gate.notcharles.ca>...
> In article <69cbbef2.0403280928.438d194f at posting.google.com>, has wrote:
> > # Library pseudocode
> > 
> > _fooRegistry = []
> > 
> > obj _Foo: # prototype object
> >     # Foo's code goes here
> > 
> > def Foo(): # constructor function
> >     newFoo = _Foo.copy()
> >     _fooRegistry.append(newFoo)
> >     return newFoo
> > 
> > 
> > Dirt simple with not an ounce of class metaprogramming in sight.
> 
> Is Foo() the standard syntax for making a new _Foo object?  If this is a
> new wrapper you just created, then it's no different than adding a
> register() method - the user has to know that something different is
> being done.
> 
> If Foo() is the standard syntax, and you're just overriding the
> implementation here, does that get inherited?  If so, this missed the
> condition that only some of the descendants should get added to the
> registry.  If not - well, inheriting the constructor seems like the more
> useful behaviour in general, so why not?

Don't think you've quite got the point of prototype-based OO yet.
There's no real 'standard syntax' for making objects; nor is there any
inheritance, classes, metaclasses, or instances. To create a new
object from scratch, execute the code that defines it. Alternatively,
duplicate an existing object.

Think of prototype-based languages as taking the more traditional,
two-tier class-based OO system and lopping off the entire upper tier.
The result is a much simpler, more direct, less formal and more
flexible approach to OO programming. If you're used to class-based
programming you may find the lack of predefined rules and formal
convention and ceremony a bit offputting. I expect Java programmers
feel the same when they first encounter Python's type system. Devise
rules to suit yourself, abstract away as little or as much as you
like. Can be quite refreshing getting right down to basics like this,
even if it's a little scary at first. :)



More information about the Python-list mailing list