Site Tools


Hotfix release available: 2025-05-14b "Librarian". upgrade now! [56.2] (what's this?)
php:design-pattern

https://www.ibm.com/developerworks/library/os-php-designptrns/index.html

The factory pattern

<?php 
interface IUser{
  function getName();
}
 
class User implements IUser{
  public function __construct($id){}
 
  function getName(){
    return 'Jack';
  }
}
 
class UserFactory{
  public static function Create($id){
    return new User($id);
  }
}
 
$uo = UserFactory::Create(1);
echo $uo->getName();
php/design-pattern.txt · Last modified: by 127.0.0.1