mardi 16 février 2016

mvc where to keep the reference to controllers?

In my program the controller just hooks keypresses with a function. So should ikeep a reference to it? E.g. keeping a reference

Model model = new Model();
View  view  = new View(model);
Controller controller = new Controller(model,view);

or no

Model model = new Model();
View  view  = new View(model);
new Controller(model,view);

Inside Controller

public Controller(Model model, View view)
{
    this.model = model;
    this.view = view;
    view.setOnKeyPressed(this::doSomething);
}

public void doSomething(KeyEvent event)
{
    System.out.println("key pressed");
}

Maybe I implemented the Controller class wrong and misunderstood mvc pattern. But with what i wrote so far there is no reason for me to keep a reference to the controller object.

Aucun commentaire:

Enregistrer un commentaire