Windows Develop Bookmark and Share   
 index > Windows Forms General > Communicating between objects in object model
 

Communicating between objects in object model

Hopefully this will make sense.

I have a class, we'll call it Class1. It contains a collection of Class2 objects, which contains a collection of Class3 objects. Class1 has a property called IsChanged. Class3 has a property called Value. Whenever the Class3.Value property is changed, I want to set the Class1.IsChanged property to True. I'm not sure how to change the property of the Class1 object when the property is changed in the child Class3 object. 

Essentially the IsChanged property at the top level object is a state flag so that the consumer of Class1 can tell by checking a single property if any of the Values in the Class3 objects have been changed.

Class1 (with IsChanged Property)
|
--Class2 (one or more of these in the Class1 object)
   |
   ---Class3 (with Value Property - one or more of these in the Class2 object)

Can anyone help with this? Thanks.
MigrationUser 1  Wednesday, March 02, 2005 3:03 PM
two ways:

1. each object should contain a reference to it's parent.  when a value in the object is changed, it sets it's own IsChanged property to true, which in turn sets it's parent's IsChanged property to true.

OR

2. each object throws an event when it has been changed.  the parent object can hook onto the changed event of it's child objects and set it's own IsChanged property to true.

you use whichever of the two architectures you prefer.  i much, much prefer #2, as you get so many more benefits in terms of ANYTHING being able to hook onto the event (plus it makes life easier if you want to implement an undo stack in your app).

hope that helps some.
MigrationUser 1  Saturday, March 05, 2005 7:08 PM

You can use google to search for other answers

Custom Search

More Threads

• requiredfieldvalidator control
• GDI+ Bounding Box Idea
• Remotely Creating community with READ_CREATE rights and adding an IP in trap destination
• 2 ToolStrips - Gap?
• listbox string justification
• Custom Control and Windows 2000 domain
• how do I access navigate to url via hyperlink using HTMLDocument?
• Datagridview Update to SQL 2005
• Disappearing controls
• RegisterAsBrowser not working in VB 2005