Robert Cummings wrote:

Feel free to ask questions

I couldn't come up with anything substantial via other examples, so I fell back on a similar
structure that Im currently using in my DB code.
The goals:
1. To be able to have the child classes to talk to one another.
2. To be able to have the parent class talk to the child class and vice versa.
3. Not have multiple references to objects (ie two classes having references to the db class for example).
4. Not really a primary goal, but have the capability to juggle one object in procedural land.


The example code meets all 3(4) goals, and Im looking for constructive critisism.
Thanks


--------

<?php

header('content-type: text/plain');

$bar = new mm;
var_dump($bar->ExecuteSQL());  // Call parent method in procedural land
var_dump($bar->DisplayPage()); // Call parent method in procedural land
var_dump($bar->foo['db']->db); // Call child variable in procedural land

// Parent class with methods that wrap child method(s)
class mm
{
   var $foo;

   function mm()
   {
       $this->foo['db']  = new db;
       $this->foo['tpl'] = new smarty;
   }

   function ExecuteSQL()
   {
       return $this->foo['db']->execute($this);  // Talking to children
   }

   function DisplayPage()
   {
       return $this->foo['tpl']->display($this); // Talking to children
   }
}

// Child class
class db
{
   var $db = 'database';

   function execute(&$mm)
   {
       return 'execute';
   }
}

// Child class
class smarty
{
   function display(&$mm)
   {
       // Talking to parent (which is capable of talking to other children)
       var_dump($mm->ExecuteSQL());

       return 'display';
   }
}

?>

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



Reply via email to