2
class ForumThread
{
    /**
     * @return bool
     */
    public function findBadLanguage ($inWhat)
    {
        return (bool)rand(0,1);
    }

    /**
     * @return
     */
    public function add ($threadName)
    {
        if (!$this->findBadLanguage ($threadName))
        {
             INSERT INTO
        }
    }
}

class ForumPost
{
    /**
     * @return
     */
    public function post ($toThreadId, $comment)
    {
        // im talking about this:
        Services::getForumThread()->findBadLanguage($comment);
    }
}

I know findBadLanguage() should be in another class, but lets suppose thats okay. Lets focus on Services::get****() calls. Is it OK to turn to a global container and get objects from it? Or to turn to a factory? Doesnt it hury Demeter's law? It says we must not use object from the outside

Cœur
  • 37,241
  • 25
  • 195
  • 267
John Smith
  • 6,129
  • 12
  • 68
  • 123

0 Answers0