note 62096 added to ref.classobj

From: Date: Mon, 20 Feb 2006 00:12:12 +0000
Subject: note 62096 added to ref.classobj
Groups: php.notes 
Request: Send a blank email to php-notes+get-104041@lists.php.net to get a copy of this message
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' ) ;


?> ---- Server IP: 66.163.161.117 Probable Submitter: 66.227.189.38 ---- Manual Page -- http://www.php.net/manual/en/ref.classobj.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+62096 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+62096&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+62096&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+62096&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+62096&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+62096&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+62096&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+62096&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+62096&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#104041) next »