I am seeking feedback from individuals with more experience than me to determine if my approach is correct. I am currently working on an Ionic3-Angular app that involves a CRUD functionality for "Clientes". From what I have researched, the recommended structure is as follows:
- Cliente Model: A class where attributes are defined.
- Cliente Service / Provider: Responsible for database communication, including retrieving, modifying, and saving data.
- Page: Where data is loaded and displayed.
The examples I have come across typically involve:
- Instantiating the Cliente model in the Page.
- Injecting the Cliente Service / Provider into the Page.
When loading data:
- Data is loaded from the Page using the Provider, then assigned to an object (of type Cliente).
Now, here's where my uncertainty lies - would it be more effective to implement data access and management directly within the Model? I have successfully completed small projects using this approach, but I haven't been able to find any existing examples of others doing the same. This leads me to question whether or not I might be mistaken. Essentially, my idea is to have a Client Class with these methods:
static load(cs:ClienteService,id):Cliente{
//Function that receives the provider and uses it to access data based on the provided Cliente ID.
}
guardar(cs:ClienteService):boolean{
// Function to save the object using the provided ClienteService parameter
}
The ClienteServicio will be injected into the Page and passed to the Model as a parameter when necessary. This way, logic checks data, etc., can all be managed within the Model itself.
I hope this explanation makes sense, and I welcome any advice from the community. Thank you very much!