Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:4570 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86081 invoked by uid 1010); 24 Sep 2003 20:20:52 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 86057 invoked from network); 24 Sep 2003 20:20:51 -0000 Received: from unknown (HELO miranda.org) (209.58.150.153) by pb1.pair.com with SMTP; 24 Sep 2003 20:20:51 -0000 Received: (qmail 27708 invoked by uid 546); 24 Sep 2003 20:20:51 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 24 Sep 2003 20:20:51 -0000 Date: Wed, 24 Sep 2003 16:20:51 -0400 (EDT) X-Sender: adam@miranda.org To: internals@lists.php.net Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: pres2 hacking and refactoring From: adam@trachtenberg.com (Adam Maccabee Trachtenberg) I posted this to the pres2 list, but either nobody read it, or nobody's interested. So, I'll try here. I've been futzing around with pres2 and I'd like to propose a change in how the objects are organized. I think this will make it easier for people to work on designing new formats and also reduce the total number of LOC. Right now, we do something like this: class _example { function _example() { /* construct */ } function display() { $this->$mode; /* mode is html, plainhtml, flash, pdf */ } function html() { /* html display */ } function plainhtml() { /* plain display */ } function flash() { /* flash display */ } function pdf() { /* pdf display */ } } This makes it really hard to work through all the tag classes because there's tons on formatting code embedded in each object. Also, many display methods for one mode are implemented by calling the same method for another mode. (i.e.: function flash() { $this->html(); }) I propose we rip all these individual display functions out of the tag objects and put them in a separate object for each display format, like so: class html { function _example(&$example) { /* html() function previously in the _example class */ } } And make the display() function be: function display($mode) { $class = get_class($this); $mode->$class($this); } Where $mode is one of html, plainhtml, etc. This, IMHO, has a few advantages: 1) By extending from one class, we can easily override just the methods we want to modify to create new display formats. (For example, the flash class only needs to implement one method since everything else is just calling the html() method.) 2) From my perspective, people generally hack on the output for one format at a time instead of one tag at a time. This consolidates all the code they're working on into one common place instead of spreading it across a whole file. 3) When new tags are added, we can just add a basic implementation in a parent display class and nothing will break. Thoughts? Comments? -adam PS: In case you were wondering, I've actually already done all this and it works "on my machine." But I've only really tested the html output; I decided to wait on flash and pdf until I got some feedback on way or another. -- adam trachtenberg adam@trachtenberg.com