1
Let’s say I have the class Veiculo
and the class Fabricante
. Each vehicle has a manufacturer as an attribute, among other attributes.
I have the views to maintain (register, edit and delete) and search vehicle and also manufacturer.
Each model class has its own controller (I decided to create 1 control per model, instead of creating a view). That is, the class controlVeiculo
will be accessed by more than one view and will have the methods
+listarVeiculos()
+salvarVeiculo(Veiculo v)
+editarVeiculo(Veiculo v)
+excluirVeiculo(Veiculo v)
(...)
Which in turn accesses the DAO classes. As well as the class controlFabricante
will have the same methods as manufacturer.
When I call the view to register vehicle, for example, I will need to list manufacturers already registered in the bank for the user’s choice. That list of manufacturers must come from where?
- create an instance of
controlFabricante
within theviewVeiculo
and call the method normally? - leave mine
viewVeiculo
only by accessing your control (controlVeiculo
) and create a method incontrolVeículo
to access theDAOFabricante
? - leave mine
viewVeiculo
only by accessing your control (controlVeiculo
) and, instead of creating a method in thecontrolVeículo
, I create an instance ofcontrolFabricante
insidecontrolVeiculo
and call the method between the controllers (since it already has a method defined in the other control, avoiding duplicating methods) - any other suggestions?
You instantiate a manufacturer model and call the method to list them,
– Leonardo
Without going through any control even? Instancio o fabricante dentro da viewVeiculo?
– Gustavo Belczak
Yes, without any controller, unless you were validating data in the controller, because normally the model is responsible for validating and saving/editing/erasing/fetching data in persistence. And no, you create an instance in the vehicle controller, in the list method, so you take the result of that instance and send it to the view
– Leonardo
Blz, thanks for your help!
– Gustavo Belczak
@Gustavobelczak The answer solved your question? Do you think you can accept it? See [tour] if you don’t know how to do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).
– Maniero