As someone from the world of java and c++, I am fascinated in a very non-sectarian way how the hook mechanism in general manages to allow modules to "override" behavior proper to the core. Dries has mentioned this in several presentations, and there is the article on OOP and Drupal in the API docs. In no way is this the place for disputing programming paradigms and their relative merits. But since someone asks for an opinion, I would like to point out that polymorphism is not simply overriding a function by the same name, it assumes that a virtual machine traverses a set of inherited objects and automatically picks out the right type, and invokes its implementation. So there wouldn't be any redundant code anywhere, and I could write code (this is the important thing) for "nodes" that would work for an "image" type inherited from node without changing anything. I am already fantasizing (and have been for some time) on what an object oriented reverse engineering of Drupal might look like, and one day it will have to be done. Right now, however, when we want to override theme behavior for a given node, we have to copy node.tpl.php to node-modulename.tpl.php and change the default behavior; and the theme function acts like a virtual machine and chooses the function corresponding to the "object" by the file name. So the theme function is actually implementing behavior proper to a virtual machine. It may be efficient in execution, but in Drupal this has to be done again and again. So it is not polymorphism, in the strict sense. I have been following much of these discussions, thinking to myself that the essence of the problem is "what is the most efficient way to make procedural event-driven (callback hook) code act like an OOP virtual machine." At some point, the only way to solve things completely will be to move to PHP5 classes or to Ruby... although in a year or so, these languages may very well converge into a single VM... But the object oriented paradigm is mandatory at some point. God knows when, things are working out pretty well without it :) Victor Kane http://awebfactory.com.ar On 1/22/07, Chris Johnson <cxjohnson@gmail.com> wrote:
Aren't we really talking polymorphism here when we say we want to use the something like the node API "toolkit" on other objects?
If I read and understand correctly, there are 2 major suggestions. One group wants to make more objects be nodes, so that this benefit is gained. Others don't want some other object types to be nodes and have suggested generalizing the node API to obtain the benefits.
Using node-like API functions on other objects sounds like polymorphism to me, which is a "solved problem" so to speak. Any Java or C++ programmers out there who might comment on this? (I only know enough Java and C++ to be dangerous. :-)