Views accessing other controllers

1

Let's say I have class Veiculo and class Fabricante . Each vehicle has a manufacturer as an attribute, among other attributes.

I have the views to keep (register, edit and delete) and fetch vehicle and also manufacturer.

Each model class has its controller (I decided to create 1 control per model, instead of creating a control by view ). That is, the controlVeiculo class will be accessed by more than one view and will have

+listarVeiculos()

+salvarVeiculo(Veiculo v)

+editarVeiculo(Veiculo v)

+excluirVeiculo(Veiculo v)

(...)

Which in turn accesses the DAO classes. As well as the controlFabricante class will have the same methods for manufacturer.

When I call view to register vehicle, for example, I will need to list the manufacturers already registered in the bank for the user's choice. This list of manufacturers should come from where?

  • I create an instance of controlFabricante within viewVeiculo and call the method normally?
  • I leave my viewVeiculo only by accessing your control ( controlVeiculo ) and I create a method in controlVeículo to access DAOFabricante ?
  • I leave my viewVeiculo only by accessing its control ( controlVeiculo ) and, instead of creating a method in controlVeículo , I create an instance of controlFabricante within controlVeiculo and call the method between the controllers (since it already has a method defined in the other control, avoiding duplicate methods)
  • Any other suggestions?
asked by anonymous 13.12.2016 / 23:03

1 answer

5

I'll answer based on what you have in the question. It may be that you have other information that makes me think differently.

I do not think I understand the MVC. You do not have to have a one-to-one relationship with anything.

Create the templates you need to manipulate the data, possibly doing the persistence.

Create the views you need to display the data, possibly each one being a screen or part of a screen, either as it is shown to the user.

Create the drivers you need to do various operations. A controller does not need to be connected to either the view or the model, it should do something that makes sense to be in a single unit.

You can have a controller only for what you want. Or you can have the operation you want inside an existing controller, if it makes sense.

Take this relationship out of your head and everything starts to clarify.

In general the controller should only do technical operations of the application. It should do the assembly of what is needed to offer to the view , usually requesting data for the model .

Who should provide data is the template.

  

This list of manufacturers should come from where?

From the manufacturers model.

  

I create an instance of the Authoring control inside the viewVehicle and call the method normally?

No, the layers must be independent, and the view should receive data passed by the controller .

  

I leave my viewVeiculo only by accessing its control (controlVecile) and create a method in the vehicle control to access the DAOFabric?

More or less. It creates a model instance within the controller to receive the data, treat and send it to view .
  

I leave my viewVeiculo only by accessing its control (controlVeiculo) and, instead of creating a method in theVehicle control, I create an instance of theVehicle control inside theVehicle control and call the method between the controllers (since it already has a defined method on the other control, avoiding duplicate methods)

I do not say I can not do this, but I have to see if it makes sense.

Maybe you need to do something other than this, but something generic, without details, is hard to say.

    
13.12.2016 / 23:19