Re: [PEPr] Comment on Networking::Net_I2C

From: Date: Mon, 10 Aug 2009 15:23:47 +0000
Subject: Re: [PEPr] Comment on Networking::Net_I2C
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-52603@lists.php.net to get a copy of this message
Samuel ROZE - D-Sites wrote: > Hello, > > Le dimanche 09 août 2009 à 18:41 +0100, Philippe Jausions a écrit : >> - Agreed with Christian, comments and error messages should be in English >> (unfortunately for some, this is the de-facto standard language) >> >> - Net_IP2Country would be a better self-explanatory name >> >> - I'd suggest to do 2 separate classes for back end SOAP vs. HTTP. >> Net_IP2Country_SOAP and Net_IP2Country_HTTP, with a >> Net_IP2Country::factory($backend) method. Your code will be much cleaner >> instead of having hooks for methods to use, and that would also allow for >> extensions (interfacing with a MaxMind's GeoIP local database for >> instance) >> > > Can you tell me how you view the organisation of my code ? At the > creation of the Net_IP2Country instance, i'll call Net_IP2Country_SOAP > or HTTP class ? Something like this: Net / IP2Country / SOAP.php HTTP.php Exception.php class Net_IP2Country { ... public static function factory($backend) { $class = 'Net_IP2Country_'.$backend; if (!class_exists($class)) { include_once 'Net/IP2Country/'.$backend.'.php'; } $instance = new $class(); return $instance; } ... } You could also do some fancier stuff in the factory, like throwing an Exception if the backend doesn't exist, or try to load a default backend depending on the PHP configuration, but that should give you the basic idea. You may also add an "$options" parameter that could be passed to the backend constructor if needs be (i.e. HTTP proxy settings, ...) -Philippe

« previous php.pear.dev (#52603) next »