How to notify children they are being removed?

How to notify children they are being removed?

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


hurcane posted on Monday, May 07, 2007

I have a use case where the child objects of a BusinessListBase must take some action when they are removed from the collection. I can't find where the framework has any kind of mechanism for making the child object aware that it is being deleted through it's parent collection.

Am I missing something? Or do I need to add a Friend method to my child object and override the Remove method of the collection to call this new method?

I was reviewing the statement on page 149 of the VB book that says that child objects must have the ability to remove themselves from the collection. I think this might apply only when data binding to a grid, which I'm not doing. Is that a correct assumption?

RockfordLhotka replied on Monday, May 07, 2007

hurcane:
I have a use case where the child objects of a BusinessListBase must take some action when they are removed from the collection. I can't find where the framework has any kind of mechanism for making the child object aware that it is being deleted through it's parent collection.

Am I missing something? Or do I need to add a Friend method to my child object and override the Remove method of the collection to call this new method?

No, there is no such notification in CSLA. You'll need to do it yourself as you describe.

Better yet, if you subclass all the CSLA base classes (which I recommend as a best-practice), you could implement this concept into your new base classes. That's only a good idea, though, if you need this sort of behavior across many/most of your objects. If you just need it in this one collection then you are best off doing it in the collection/child objects themselves.

hurcane:

I was reviewing the statement on page 149 of the VB book that says that child objects must have the ability to remove themselves from the collection. I think this might apply only when data binding to a grid, which I'm not doing. Is that a correct assumption?

That is correct - this only applies to new child objects that are removed from a grid control, and even then really only in .NET 1.x, or if you use .NET 1.x style data binding in .NET 2.0.

Copyright (c) Marimer LLC