Is it just me, or is there a screaming need for an "Advanced OOP Techniques" article? 🙂
Like many programmers who are moving to OOP, I'm finding myself repeating a lot of coding, so I'm trying to sew together a nice "base" class with a few good extensions that cover most of my needs, which you all are familiar with:
base (error handling, timing, etc.)
adodb (or some database abstraction layer)
FastTemplate (or some template scheme)
BUT, I'm having a problem when I try to access method from one extended class in another extended class. For example:
class base {}
class template extends base {}
class news extends base {}
And now a method in the "news" class needs to use a method in "template", say, $this->parse(). Well, this doesn't work. PHP complains that this is an undefined function...
Ok, so one work-around is to instantiate the class ( $tpl = new template; ) within the calling file (the file that is calling this classes), then globalizing $tpl in the news class, thus making $tpl->parse(); available to news.
This, however, seems to be defeating the purpose of the whole "oop-saves-you-lots-of-time" thing.
Enter work-around #2: put ALL the methods you will need in the "base" class! That way, all the methods you know you'll need a LOT are accessible via $this->whatever.
Ok, this is a little bit better, but it does make for a VERY large base class (couple thousand lines), but then, for large complicated sites, this is a good thing, right?
So the question is, am I doing something wrong here? Is there really a way for an extended class to access methods that are in another extended class WITHOUT going through the steps of declaring each extended class individually, globalizing each object, then calling the methods.
Oh, and before anyone posts anything along the lines of "it's obvious you don't know anything about class design..." let me be preemptive: I DON'T know anything about class design, and I AM a brand new programmer, so an explanation (however brief) of WHY my design stinks would be greatly appreciated 🙂.
Thanks in advance!
-DLST