Prototype OO

sam sam at mas.pl
Thu Mar 20 16:44:43 CET 2008


Bruno Desthuilliers napisał(a):

> Most of the arguments in favor of prototypes seems to come to, mainly:
> 1/ it lets you customize behaviour on a per-object base
> 2/ it removes the mental overhead of inheritance, classes etc
> 
> Point 1. is a non-problem in Python, since you can already add/replace 
> methods on a per-objec basis (ok, with a couple restrictions wrt/ 
> __magic__ methods and such).
> 
> Point 2. is not (IMHO) such a problem in Python, where inheritance is 
> mainly an implementation detail (it's not needed for polymorphic 
> dispatch to work) and class hierarchy tend to be very flat, when they 
> even exist.
> 
> Mainly, Python's object system is actually quite close to javascript 
> here. That is, you get more or less the same flexibility. And a couple 
> of powerful features you don't have with javascript (like hooks in the 
> attribute lookup mechanism), too.

Thanks for precise opinion and spending your time.


I think that when you use statically typed language, than you have to define 
classes, because compiler has to know what is allowed to do with instances of 
that class.

But when you use dynamically typed language, then classes are redundant, because 
object is looked at when it is referenced. Dynamically typed language needs only 
objects hierarchy and you can add properties (methods, values) to that object 
during program execution.

In dynamically typed language when you create object A that is inherited from 
another object B, than object A knows that B is his predecessor. So when you 
reference A.prop, then prop is looked in A first, then in B, then in 
predecessors of B, and so on.

Having object A you can access its predecessor B. When you have access to object 
B, then you can add properties to it and these properties could be accessed by 
all other objects inherited from B.

You can do all these things in Python. But why it uses classes?

So you can say: "CLASS BASED PROGRAMMING" == "STATICALY TYPED LANGUAGE"








More information about the Python-list mailing list