|
Posted by Pavel Lepin on 11/09/07 11:20
Follow-ups set to comp.object
Gordon <gordon.mcvey@ntlworld.com> wrote in
<1194601048.553776.222520@d55g2000hsg.googlegroups.com>:
> The current plan is to have a hierarchy of classes going
> from the general to the specific and inherit and
> override/extend functions as necessary to achieve the
> desired results. At the top of the chain is a CMS item
> object that defines props and methods that are common to
> all items that will be stored by the CMS: Creation/last
> modified dates, summaries, filesystem paths etc. From
> that I dreive classes for specific types of CMS data.
> Documents, images and directories all decend directly from
> the CMS item class.
>
> As I was designing I originally intended for there to be a
> site class that inherited from the item class, but as the
> design progressed I realised that a site is basically a
> special case of a directory and therefore should be
> derived from the directory class.
>
> But here I hit a snag, because I need to access a method
> in the item class while bypassing the same method in the
> directory class.
Then your design is, well, bad. What parent class extends is
its implementation detail, therefore you shouldn't rely on
it.
> In the item class is a method that inserts some data into
> the items table of the database. In the directory class
> this method is extended by another method of the same
> name. This method runs the method in the parent class
> with parent::method(), then does the extra SQL queries
> that it needs to do for creating a directory.
>
> The site class, however, uses a different pair of tables
> (item and site) to the directory class (item and
> directory).
So either make them use the same table (if Site truly is-a
Directory), or extend Item instead of Directory.
> This means that the method in the site class needs to call
> the parent's parent method directly without calling the
> parent's method. I tried both parent::parent::method()
> and parent::parent -> method() but both of these threw an
> error
I'm actually unaware if it's possible to do in PHP, because
I wouldn't do that anyway for reasons outlined above.
If you're thinking along the lines of "but Site really is a
lot like Directory" - you might as well be right, but there
are cleaner solutions to the problem. Strategy pattern
comes to mind.
--
....also, I submit that we all must honourably commit seppuku
right now rather than serve the Dark Side by producing the
HTML 5 spec.
[Back to original message]
|