What is a model and what is not a model php -


i'm quite confused on how build models, failed understand last 9 months. although reading , watching references , @teresko gave me.

to further narrow down question, i'll give example of how did before.

lets have student entity has student_number, first_name,last_name`

i create called model, (my professor did same, know quite wrong). don't know if professor knows value objects, do.

private $student_number; private $first_name; private $last_name;  public function setstudentnumber($sn) {$this->student_number = $sn} public function getstudentnumber() {return $this->student_number} ... , on other properties 

if correct, setters , getters classified value object pattern, can used this:

$s = new student(); $s->setstudentnumber(143); $s->setfirstname('fooname'); $s->setlastname('barname'); 

and pass in data access object (studentdao) this:

$sdao = new studentdao($s); $sdao->add(); 

where dao extends database class, can crud example.

the question is, well, i'm pretty sure lot of scolding here missed many principles, those? how create models? thank you! well, know many answers tell datamappers, factories , stuffs, cannot understand well.

model:

  • dao: connects datasource (i.e. file, database/sql, webservice etc).
  • mapper: maps external data dao internal entities/domain objects (getters/setters), , internal data external.
  • service: business logic.

controller:

  • action calls service layer (not mapper or dao)

dependency: service -> mapper -> dao i.e. dao injected mapper, mapper injected service

this way change datasource database webservie & business logic stay same.

nb: recommend, dao & mapper both have interface


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -