The factory method pattern is an object-oriented creational design pattern to implement the concept of factories and deals with the problem of creating objects (products) without specifying the exact class of object that will be created.
<?php
interface UserInterface
{
function get();
}
class User implements UserInterface
{
private $user;
public function __construct($user)
{
$this->user = $user;
}
public function get()
{
return $this->user;
}
}
class UserFactory
{
public static function create($user)
{
return new User($user);
}
}
$user_factory = UserFactory::create('John');
echo $user_factory->get();
?>