Notify Child that Parent has Changed

Notify Child that Parent has Changed

Old forum URL: forums.lhotka.net/forums/t/7840.aspx


xAvailx posted on Wednesday, October 21, 2009

Yeah, it is backwards from most questions here...but here is my scenario.

Parent (EditableRoot)
> Child (EditableChild)

The child object has rules that are dependent on the state of the parent. That part I've figured out thanks to other folks asking similar questions.

Now my question is when my parent changes its state, I need to notify the child it has changed. I was thinking of having a method in my child class that calls CheckRules.

I think this will work, but want to know how others have solved this scenario. Any thoughts?

Fintanv replied on Thursday, October 22, 2009

That is the method I have used.  Just create a child method to check the appropriate rule(s).  I usually make the rule internal in scope.

Henrik replied on Friday, October 23, 2009

You are creating a pretty tight coupling here. Usually a child shouldn’t know anything about it’s parent, whereas a parent “can” know about it’s children.

Maybe your scenario requires this, but you’ll have to provide more information. Anyway to solve your immediate problem you could override the parent’s OnPropertyChanged, in which you notify each child that the parent has changed. Then each child can decide whether or not to act upon this info.

Cheers
/Henrik

Copyright (c) Marimer LLC