Re: [PHP] OOP for Web Programming Paradigm

2003-01-12 Thread olinux
I'm no OOP programmer but maybe extend your class to
include methods for each situation.

something like this:

function countSingle($cid)

function countMulti($cidArray)

function countAll() 


HTH,
olinux


--- Victor [EMAIL PROTECTED] wrote:
 Hello. I have this question. When I program, I try
 to create a class for 
 each table. Example below.
 
 Now what some complain about, and logically so, is
 that this might 
 impose an overhead (I load all data even if I just
 need a counter and 
 NOT description).
 
 So I say we can make a STATIC version of each
 Accessor with $cid as 
 argument; But then they say what if i want to load
 an array of all 2000 
 counters, for example. I say first get all the
 $cid's, then in an array, 
 load a class for each one, etc.. That however makes
 lots of SQL calls 
 instead of one big one. I suppose I can get all data
 and then load it 
 into classes, but that seems like a bad approach,
 especially for 
 calculated values.
 
 What I am curious about is what paradigms do you
 guys use to address 
 these issues? Is my paradigm good and it's worth to
 just provide static 
 methods for frequently necessary fields to reduce
 overhead, or is there 
 a better way of dealing with this stuff?
 
 class Counter
 {
 var $db;
 
 var $cid;
 var $counter;
 var $descr;
 
 /**
  * Default Constructor
  * @param int $cid - Counter ID
  */
 function Counter($cid=false)
 {
global $db;
$this-db = $db;
if (isset($cid)  $cid) $this-load($cid);
 }
 
 /**
  * Description
  * @param int $cid - Counter ID
  * @return bool
  */
 function load($cid=0)
 {
if (!$cid) return false;
 
$q = SELECT * FROM counter WHERE cid =
 $cid;
$r = $this-db-getRow($q); // Using PEAR
 here.
 
if (!DB::isError($r)) {
   $this-cid = $r[cid];
   $this-counter = $r[counter];
   $this-descr   = $r[descr];
   return true;
}
return false;
 }
 


#
 # Accessor Methods


#
 function getCid() { return $this-cid; }
 function getCounter() { return $this-counter; }
 function getDescr()   { return $this-descr; }
 


#
 # Mutator Methods


#
 function setCid($v) { $this-iaid= $v; }
 function setCounter($v) { $this-counter = $v; }
 function setDescr($v)   { $this-descr   = $v; }
 
 // Many other methods, etc Static methods,
 etc...
 }
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] OOP for Web Programming Paradigm

2003-01-12 Thread Victor
olinux wrote:

I'm no OOP programmer but maybe extend your class to
include methods for each situation.

something like this:

function countSingle($cid)

function countMulti($cidArray)

function countAll() 


HTH,
olinux

Hmm, yes, that's an interesting idea. Except perhaps include the first 
arg as a by-refrence return variable, so that func can return true 
false. Yeah, I think that's not bad. Still, would have to have static 
accessors, but oh well...


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php