Undocking Controller GUI

0

Hello.

Consider:

  • a Visio object - GUI (Graphical User Interface);
  • a Controller object, which handles system events, GUI actions, and
  • model objects

Consider that a Vision object receives a Controller object as a parameter:

 Controlador controlador = new Controlador(repositorio);

 Visao visao = new Visao(controlador);

Consider also, that the role of the Controller is to pass system events to the objects of the Model, that is, an action X in the GUI should be passed on to the Controller, which in turn will pass on to the Model.

One way to decouple a Vision from a Controller would be to extract a common interface for a Vision to implement, since the goal is to exchange / replace one Vision with another.

Question: Would it be correct to create an interface for both Vision and Control to implement?

See:

public interface VisaoInterface {
    void entrarAlgo(Integer algo);
}

public class Janela extends JFrame implements VisaoInterface{
//    private Controller controller; 
// ou a própria interface
private VisaoInterface controller;


    @Override
    public void entrarAlgo(Integer algo) {
        this.controller.entrarAlgo(algo);
    }
        // objetos GUI
    private void ButtonEntrarAlgoActionPerformed(ActionEvent evt) {                                         
        this.entrarAlgo(Txt.getText());        
    } 
}

public class Controller implements VisaoInterface{
    @Override
    public void entrarAlgo(Integer algo) {
        this.modelo.fazerAlgo(algo);
    }
}
    
asked by anonymous 23.11.2018 / 20:44

0 answers