Reply to oo arcitecture (Re: [PHP] Extending a Class)

Your name:

Reply:


Posted by Ben Edwards on 01/21/05 19:20

Your email prompted me to think about architecture. What I have is;_

a database class which is the only class with direct access to the database.

a table class, which is passed the database class on instantiation.

a presenter class which is passed the table class during instantiation.

This means that if you want to render html you use and instance of the
presenter class but you can also call methods on the database object
directly to, for example, update the database. You will probably want
a valuator class to validate user input. If you have and extended
data dictionary (i.e. validation rules in the database) you would have
a extended data dictionary class you pass to the valuator (which
itself would have the database passed to in on instantiation).

What I cant quite work out is what to do about html related methods
that do not relate to a database table (i.e.rendering table
top/middle/bottom). Maybe you want a html class which is a composite
of the presenter class or can be accessed directly for non-table
related presentation?

Ben

On Thu, 20 Jan 2005 18:17:47 -0800, Phillip S. Baker
<phillipsbaker@gmail.com> wrote:
> Greetings all,
>
> I have a class I use for MySQL connection and functions.
>
> I also have a class that I use to create Paged Results.
>
> The paged results class connects to a DB and uses allot of sql calls to make
> this happen. I am noticing that it does allot that the MySQL class does.
>
> What I would like to do is to Have the paged results extend the MySQL class
> so it can use the functions within that class so I can keep them updated in
> just one place. How would I go about doing that?? Is it as simple as
> something like this (this is shortened for convience)??
>
> class Mysql {
> var $results;
> var $dbcnx;
>
> function Mysql($query, $cnx) { // Constructor function
> $this->dbcnx = $cnx;
> if (!$this->results = @mysql_query($query))
> $this->_error("There was an error with executing your query. Try again
> later.", $query);
> }
> }
>
> class PageResultSet extends MySQL {
> var $results;
>
> function PageResultSet ($query,$pageSize,$resultpage,$cnx) {
>
> $this->results = @mysql_query($query,$cnx) or $this->_error('Error Running
> your search. Try back later.', $query);
> $this->pageSize = $pageSize;
> if ((int)$resultpage <= 0) $resultpage = 1;
> if ($resultpage > $this->getNumPages())
> $resultpage = $this->getNumPages();
> $this->setPageNum($resultpage);
> }
> }
>
> I would like to be able to pass the results from the MySQL class to the
> PageResultSet class without have to do the query over and such.
> How would I go about coding that? I am not clear on that.
>
> Also can I extend a function in PageResultSet that is started in MySQL??
> In MySQL I have
> function fetchAssoc() {
> if (!$this->results) return FALSE;
> $this->row++;
> return mysql_fetch_assoc($this->results);
> }
>
> In PageResultSet I have
> function fetchAssoc() {
> if (!$this->results) return FALSE;
> if ($this->row >= $this->pageSize) return FALSE;
> $this->row++;
> return mysql_fetch_assoc($this->results);
> }
>
> Can I just write something like within PageResultSet
> function fetchAssocPRS extends fetchAssoc () {
> if ($this->row >= $this->pageSize) return FALSE;
> }
>
> Thanks for the help.
>
> --
> Blessed Be
>
> Phillip
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--
Ben Edwards - Poole, UK, England
WARNING:This email contained partisan views - dont ever accuse me of
using the veneer of objectivity
If you have a problem emailing me use
http://www.gurtlush.org.uk/profiles.php?uid=4
(email address this email is sent from may be defunct)

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация