Wygląda to mniej więcej tak:
<?php abstract class user{ protected $_id; protected $_privileges; protected $_is_logged; protected $_login_string; /** * Konstruktor * */ public function __construct($login_string){ $this->_login_string = $login_string; // logowanie, sprawdzenie uprawnien } // end of __construct /** * Sprawdzenie czy usr jest zalogowany * * @return boolean $this->_is_logged */ public function isLogged(){ return $this->_is_logged; } // end of isLogged /** * Pobranie uprawnień danego usr * * @return int $this->_usr_privileges; */ public function getPrivileges(){ return $this->_usr_privileges; } // end of getPrivileges /** * Pobranie błędów * * @return array $this->_errors; */ public function getErrors(){ return $this->_errors; } // end of getErrors } // end of user class class worker extends user { public function __construct($login_string){ parent::__construct($login_string); } /** * Rozpoczęcie pracy * */ public function in(){ // dodanie do bazy wejscia } // end of in /** * Zakończenie pracy * */ public function out(){ // dodanie do bazy wyjscia } // end of out }// end of worker class class adm extends user { public function __construct($login_string){ parent::__construct($login_string); } public function addWorker(){} public function saveWorker(){} public function editWorker(){} } // end of adm class ?>
I teraz tak: mam formularz logowania. No i nie wiem której klasy tworzyć egzemplarz. Bo na początku nie wiemy czy loguje sie usr, czy adm.
Mogę robić tak, że tworzę obiekt klasy worker, sprawdzam uprawnienia, jesli są odpowiednie, to tworzę obiekt adm, a usuwam worker. Ale moim zdaniem to jest dość głupie, a na pewno niepoprawne.
Może ktoś z dobrym sercem pomoże?
