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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -