php - Do you think its worth to make one more classes from an "observer" object? -
there news
, newstranslations
. every time new
created, @ least 1 translation
should exists:
class newsmodel { public function add() { $newid = sql insert news $this->notifyadd ($newid); } } class newstranslationmodel { public function add ($newid) { sql insert } public function notifyadd($newid) { $this->add ($newid); } } $news = new newsmodel(); $newstranslation = new newstranslationmodel(); $news->attach ($newstranslation);
but in way, feel newstranslationmodel
has responsibilities. if write this:
class newsmodel { public function add() { $newid = sql insert news $this->notifyadd ($newid); } } class newstranslationmodel { public function add ($newid) { sql insert } } class newstranslationobserver { private $newstranslation; public function __constructor ($newstranslation) { $this->newstranslation = $newstranslation; } public function notifyadd($newid) { $this->newstranslation->add ($newid); } } $news = new newsmodel(); $newstranslation = new newstranslationmodel(); $news->attach (new newstranslationobserver($newstranslation));
what think? better approach? because saw many examples saw separating
Comments
Post a Comment