Someone advised me that for an Ionic project, it is necessary to use a service for each object.
Here are my models:
export class Document{
idDocument: number;
listFields: Fields[];
}
export class Field{
idParentDocument: number;
idLinkToOtherDocument: Document;
}
And here are my services :
export class DocumentService{
constructor(private http: httpService, private fieldService: FieldService){}
getFields(document: Document){
this.fieldService.getFieldsByDocumentId(document.id);
// Retrieve the fields of the document
}
getDocument(id: number){
// Retrieve the document and its fields
}
}
export class FieldsService{
constructor(private http: httpService, private documentService: DocumentService){}
getParentDocument(field: Field){
// Retrieve the parent document of the field
}
getLinkedDocument(field: Field){
// Retrieve the linked document of the field
}
getFieldsByDocumentId(id: number){
// Retrieve the fields by document Id
}
}
Sometimes I encounter situations where I need to access objects from other objects, as shown in my example. However, this often leads to circular dependencies. In Java, you could simply call the functions, but in Angular, it's not straightforward. I am contemplating reverting to my previous design pattern where all functions were within objects instead of services, requiring me to pass all other services (database service, server service...). This would result in a significant refactoring effort for something I was told was bad design. Personally, I find it more convenient with object services as I have easy access to all services without passing them as arguments.
What do you think I should do?