Passing parent object to child objects #2947
-
Hi, FieldManager.UpdateChildren(this); We only need the primary key 'id' in child objects, so could we change the code to FieldManager.UpdateChildren(id); Kind regards |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is a choice you make based on abstraction and dependency management. Yes, you can pass in just the id, making the choice that the parent knows what the child needs. And if that changes in the future, then you change the calling code. Or you pass in the parent reference, making the choice that the parent doesn't know what the child needs, and allowing the child to pull whatever data is necessary. I don't know that either is "correct" - it is a choice. |
Beta Was this translation helpful? Give feedback.
This is a choice you make based on abstraction and dependency management.
Yes, you can pass in just the id, making the choice that the parent knows what the child needs. And if that changes in the future, then you change the calling code.
Or you pass in the parent reference, making the choice that the parent doesn't know what the child needs, and allowing the child to pull whatever data is necessary.
I don't know that either is "correct" - it is a choice.