jeudi 14 avril 2016

Which pattern to use and how to use it when I have Controller, Business Logic, and Repository?

Using MVC I have something like this:

class Controller
{

    //returns View
    function indexAction()
    {
        $data = $this->getData($this->id);

        $view = new ViewModel();
        $view->setVariable('data' => $data);

        //used to render HTML template + data above later on
        return $view;
    }


    //gets data from DB 
    //currently also does business-proprietary computation on data 
    function getData($id)
    {
        //repository/dao pattern
        $data = $this->repository->getData($id);

        //Business Logic "derivation"
        foreach ($data as $datum)
        {
            //that does not go into "Controller
            //that does not go into "Repository"
            //but where does it go? - that's my question    
            $derivedData[] = (new Business())->doLogic($datum);               
        }

        return $derivedData;
    }
}

Recap

I used Controller to get my data out of DB using Repository pattern, then placed received data into view. But business-related computations are left stranded.

Question

Where do I place my business logic computations that act on the data gotten from repository? The derived data which is to return to Controller later, to be placed into View?

Aucun commentaire:

Enregistrer un commentaire