I am trying to create a simple factory pattern demo in PHP. I am not sure if my codes are the best practice. It seems that I have some duplicated codes but I am not sure how to improve it. Basically, I want to create 3 types of accounts (basic, premium and vip). Please advise. Thanks a lot.abstract classabstract class User {    function __construct() {        $this->db= new Database('mysql','localhost','mvcdb','root','');    }    abstract function checkUser();    function showAccountCredit(){        return $this->credits;    }    function getUserName(){        return $this->username;    }}I have 3 different user account types:Basic Accountclass BasicUser extends User {    function __construct($username) {        parent::__construct();        $this->username=$username;        $this->credit='10';        $this->accountType='Basic Account';        $data=$this->checkUser();        if(!empty($data)){            echo 'The username: '.$this->username.' already exists<br>';            return false;        }        $array=array('username'=>$this->username, 'password'=>'password','credit'=> $this->credit,'accountType'=>$this->accountType);        $this->db->insert('user',$array);    }     function checkUser(){        $array=array(':username'=>$this->username);        $results=$this->db->select('SELECT * FROM USER WHERE username=:username',$array);        if(!empty($results)){        $this->credit=$results[0]['credit'];        $this->accountType=$results[0]['accountType'];        }        return $results;    }    function showAccountCredit() {        echo 'Username: '.$this->username.'<br>';        echo 'Account Credit: '.$this->credit.'<br>';        echo 'Account Type: '.$this->accountType;    }}Premium Accountclass PremiumUser extends User {    function __construct($username) {        parent::__construct();        $this->username=$username;        $this->credit='100';        $this->accountType='Premium Account';        $data=$this->checkUser();        if(!empty($data)){            echo 'The username: '.$this->username.' already exists<br>';            return false;        }        $array=array('username'=>$this->username, 'password'=>'password','credit'=> $this-                   >credit,'accountType'=>$this->accountType);        $this->db->insert('user',$array);    }     function checkUser(){        $array=array(':username'=>$this->username);        $results=$this->db->select('SELECT * FROM USER WHERE username=:username',$array);        if(!empty($results)){        $this->credit=$results[0]['credit'];        $this->accountType=$results[0]['accountType'];        }        return $results;    }    function showAccountCredit() {        echo 'Username: '.$this->username.'<br>';        echo 'Account Credit: '.$this->credit.'<br>';        echo 'Account Type: '.$this->accountType.'<br>';    }}VIP account:class VipUser extends User {    function __construct($username) {        parent::__construct();        $this->username=$username;        $this->credit='1000';        $this->accountType='VIP Account';        $data=$this->checkUser();        if(!empty($data)){            echo 'The username: '.$this->username.' already exists<br>';            return false;        }        $array=array('username'=>$this->username, 'password'=>'password','credit'=> $this->credit,'accountType'=>$this->accountType);        $this->db->insert('user',$array);    }     function checkUser(){        $array=array(':username'=>$this->username);        $results=$this->db->select('SELECT * FROM USER WHERE username=:username',$array);        if(!empty($results)){        $this->credit=$results[0]['credit'];        $this->accountType=$results[0]['accountType'];        }        return $results;    }    function showAccountCredit() {        echo 'Username: '.$this->username.'<br>';        echo 'Account Credit: '.$this->credit.'<br>';        echo 'Account Type: '.$this->accountType;    }}UserFactory classclass UserFactory {    static function create($username,$accountType){        $accountType = strtolower($accountType);        switch($accountType){        case 'basic': return new BasicUser($username);        case 'premium':return new PremiumUser($username);        case 'vip': return new VipUser($username);        default :return new BasicUser($username);        }    }index.php$user1= UserFactory::create('Jerry', 'Vip');$user1->showAccountCredit();$user2= UserFactory::create('Bob', 'Basic');$user2->showAccountCredit();$user3= UserFactory::create('Betty', 'premium');$user3->showAccountCredit();
Simple Factory Pattern Demo
php;object oriented