If someone can help me, I have a question that has been consuming me a lot in recent days and is psychologically locking my studies (hehehhe) MVC and DAO with multiple tables. I will 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:
Here is the data schema, the bank's logical model:
ThetableitemhasrelationtoUnitsincetheitemcanhavedifferentUnitofMeasure.
TheitemtablealsobindstotheComparedItemstablewhichinturnbindstoCompare.
IhavetheComparedItemstablebecauseacomparisoncanbemadewithseveralitems.
Italsofollowsmypackageswithclasses.
Example:
Butter A - 250 g, $ 3.25
Butter B - 180 g, $ 2.80
I need to know which one is cheaper, so I need to know the value of each gram of butter A and B, so I'll know exactly which one is the cheapest.
My main doubts are as follows:
1 - MVC - Model, View and Controller, well:
- Model = Are my business models as I have calculations to perform on certain items, I would have within a Model a class called Comparison that will get the objects that have relation Item - Comparison Items - Compare.
Does Model Really Work? I see many people putting here the objects POJO (Car, Post, Rental ...)
-
View = I have no doubts !!!
-
Controller = Serves to intermediate the view with the bank (DAO). In the case of using this concept on Android would it be to control the lists and insertions in the various tables that relationships need? In the case I'm going to join in the controller_comparacao for example the process of insertion of each entity and the IDs generated by the inserts I'll put it inside the Compares table along with the Compared Items?
2 - DAO - Data Access Object
-
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;
... }
As I mentioned in the MVC Model I see a lot of people creating POJO objects in the model folder, I believe the correct thing would be to create a package named POJO, VO, PO for example and create their entities there, this helps DAO , this correct I think so?
What is the best way to build these POJOs in relation to linking to another entity (Relationship). I use an Integer as in the above example OU:
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;
...
}