newbie question

Markus Schaber markus at schabi.de
Thu Aug 23 04:23:41 EDT 2001


Hi,

> Runtime typing can be immensely useful in real applications,
> especially were proxying is involved. Imagine that you are doing some
> work in XML and using various XML libraries i.e. minidom, PyXML,
> Pyana, etc. Each of these has their own DOM implementation and none
> share a common base class. In Python, they can all be used
> interchangeably because their types are not relevant. They all
> implement the same methods with the same semantics so they are
> equivalent. In a static language, you would have to write code to
> proxy between all of these DOM implementations (*). Painful.

The correct way would be to create a difference between type hierarchy 
and code reuse inheritance. This way, you can statically type, but have 
different implementations of this type. Java Interfaces go a little 
step into this direction, but sufficient for some cases.

> * Java helps you out here a bit through their runtime reflection APIs.
> But they are almost as cumbersome as just writing the proxy code.

The java'ish way would be to define the API as Interfaces, and then 
have the appropriate classes implementing those interfaces.

-- 
1) Customers cause problems.
2) Marketing is trying to create more customers.
Therefore:
3) Marketing is evil.  (Grand Edwards in comp.lang.python)



More information about the Python-list mailing list