Re: [PEPr] Comment on File Formats::iCal
| From: | Greg Beaver | Date: | Sun, 05 Jun 2005 03:05:36 +0000 |
| Subject: | Re: [PEPr] Comment on File Formats::iCal | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-37967@lists.php.net to get a copy of this message | ||
Gregory Szorc wrote:
> This solution, although not following proper coding etiquette, is the
> best I can think of for PHP 5. The File_iCal_BaseComponent classes
> serve to define methods to manipulate different properties present in
> multiple calendar components. As you can see from the inheritance, some
> properties, and thus the methods associated with these properties can be
> inherited by a number of different types of components (event, alarm,
> todo, journal, timezone). Many properties are shared among a common
> group of components (event, todo, and journal is one). However, some
> properties are shared among unique combinations of components. I would
> define these methods in a base class, but the unique combinations of
> components would require multiple inheritance, which PHP does not yet
> support. I "solve" the problem by declaring the variables in the
> abstract base class as private and the methods as protected. If a
> sub-class needs access to the method, I override the method as public
> and make a call to the base class function. This results in a little
> overhead per class, but prevents me from having to define the methods at
> multiple locations. If anyone can think of a better way to solve the
> problem, I am all ears.
What if you have a base class containing only the 100% common stuff,
then have subclasses containing the things that apply to various
classes? In other words, the subclass File_iCal_BaseEvent could contain
the stuff common to event, todo and journal. Another group of
components could have their common stuff. This way, you can have the
necessary duplication between the sub-classes (the BaseEvent may have
methods/properties in common with another sub-class), without having to
duplicate tons of methods. Basically, it would make sense to figure out
the hierarchy, and how the groups fit and overlap (maybe something like
a Venn diagram would help here). Then, design the classes to match what
you've found.
I haven't done this, so I could be completely wrong, but I think you'll
find it is better to do it this way because you'll also save memory -
PHP allocates space for every declared variable and fills it with a NULL
value. Basically, it's a bunch of wasted space in the classes that
don't use the stuff you have in the base class. Since there will be
lots of replication of the base class's stuff, I have a hunch that
memory use could become an issue on some sites.
Greg