9
If anyone can help me, I have a question q has been consuming me a lot in recent days and is psychologically locking my studies (hehehehhe) MVC and DAO with multiple tables. I’m going to put here a model, an idea and then evolve my doubts:
We imagine a system of price comparison between products that a user inserts the data to make the comparison process:
Follow the data schema, the logical model of the database:
The item table is related to Unit since the item may have different Unit of Measure.
The item table is also linked to the Compared Items table which in turn connects to Compare.
I have the table Compared Items because a comparison can be made with several items.
Follow also my packages with the classes.
Example:
Butter A - 250 g, R$3,25
Butter B - 180 g, R$ 2,80
I need to know which of the two is cheaper, so I need to know the value of every gram of butter A and B, so I’ll know exactly which is the cheapest.
My main doubts are as follows::
1 - MVC - Model, View and Controller, as well:
- Model = Are my business models as I have calculations to perform on certain items, I would have within Model a class called Comparison that will receive the objects that have relation Item - Itenscompared - Compare.
Is that really what Model’s for? I see many people putting here the objects POJO (Car, Post, Rental...)
View = No doubt!!!
Controller = Serves to intermediary the view with the bank (DAO). In case to use this concept on Android would it be to control the lists and insertions in the various tables that relationships need? In case I will join inside the controller_comparison for example the process of insertion of each entity and the Ids generated by the inserts I will put inside the table Compares together with the Compared Items?
2 - DAO - Data Access Object
As I said in the MVC Model I see many people creating inside the folder model POJO objects, I believe that the correct thing would be to create a package with name POJO, VO, PO for example and create their entities there that helps in DAO, this correct I think so?
When I create a POJO object such as Item, it has:
public class Item {
Integer _item_id; String item_descricao; Float item_preco; Float item_quantidade; Float item_preco_unidade; String item_cod_barras; Integer fk_unidade_medida;
... }
What is the best way to build these Pojos in relation to the connection with another entity (Relationship). I use an Integer as in the above example OR:
public class Item {
Integer _item_id;
String item_descricao;
Float item_preco;
Float item_quantidade;
Float item_preco_unidade;
String item_cod_barras;
UnidadeMedida unidade_medida;
...
}