Let's say we have 3 classes: ChildFromApi, Child (for sake of simplicity, hydrated ChildFromApi) and Parent. There is relation between them:
Child {
parent: Parent;
childFromApi: ChildFromApi;
//should remove this particular child from parent's childrenFromApi and children lists
delete(): void;
constructor(parent: Parent, childFromApi: ChildFromApi)
}
Parent {
childrenFromApi: ChildFromApi[];
//mapped version of childrenFromApi
children: Child[];
constructor(childrenFromApi: ChildFromApi[])
}
Is it good practice in OOP to make in Children methods like delete()
that are capable of mutating Parent? Or should I better create method deleteChild(child: Child): void
in Parent?
I am a frontend developer and from perspective of my tasks, allowing children to self-delete seems very convenient
Aucun commentaire:
Enregistrer un commentaire