I want to do this question for people who have more experience than me to know if my planning is right or not.
We are going to suppouse we are develping and Ionic3-Angular app where we have a CRUD for "Clientes". I have read that right way is:
- Cliente Model: Class where I define attributes.
- Cliente Service / Provider: It will manage database communication getting, modifing and saving data.
- Page: Where I call load datad and show.
All examples I found should be:
- They instance model Cliente in Page.
- They inject Service / Provider Cliente in Page.
To load data:
- From Page they load data throw Provider and it assign data to an object (type CLiente).
Now I'm going tolaunch my doubt. Could be better implement data access and manage directly in Model?. I have done small projects with this but I can found any example where people do this and may I'm in a mistake. I mean:
For exmple I'll have a Client Class with these methods:
static load(cs:ClienteService,id):Cliente{
//function that receive provider and use it to access data with the other parameter (id of the Cliente)
}
guardar(cs:ClienteService):boolean{
// function to save object throw the ClienteService parameter
}
ClienteServicio will be injected in Page and will be passed to Model as parameter function if necesary. By this way logic, check data, etc.. will be manage at Model.
I hope I explained it and get advice from community. Thanks so much
Aucun commentaire:
Enregistrer un commentaire