note 62096 deleted from ref.classobj by betz
| From: | betz@php.net | Date: | Mon, 20 Feb 2006 01:58:13 +0000 |
| Subject: | note 62096 deleted from ref.classobj by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-104046@lists.php.net to get a copy of this message | ||
Note Submitter: jeff dot dorsch at gmail dot com
----
zabmilenko - here is a solution that expands on the one provided by ia using the factory pattery,
this is in PHP 4.1, rewrite it to properly use an interface for DB instead of extending it. Learn
patterns, they
rock. <?php // This
should be an interface in PHP 5 or an abstract // interface or
something class DB { var $connection
; function Connect() {}
} // This should implement DB
in php 5 class dbMySQL extends DB { function
Connect() {...} } class dbPGSQL extends
DB { function Connect()
{...} } class
DBFactory { function &Create( $dbType
) { switch( $dbType )
{ case 'MySQL': return new
dbMySQL() ; break ; case
'PGSQL': return new dbPGSQL() ;
break ; default: die(
'bad dog! bad!') ; }
} } $db = &
DBFactory::Create( 'MySQL' )
; ?>