472,780 Members | 1,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 software developers and data experts.

Communicating property changes

This posting is for the Google crawler and requires no response.

I have created a multi-level object hierarchy, in which the root object
needs to be notified whenever any property of any object in the collection
changes. I wanted to enable this communication without passing child objects
references to their parents. Those references increase the internal coupling
of an object hierarchy and should be avoided where possible.

Here is how I solved the problem:

Each item (non-collection) class in the hierarchy implements the
INotifyPropertyChanged interface--it fires a PropertyChanged event when any
property in the object changes.

All collection classes in the hierarchy derive from the BindingList<T> base
class, which means they implement the IBindingList interface. As a result,
they listen for property changes in the objects they contain, so long as
those objects implement the INotifyPropertyChanged interface. The collection
fires a ListChanged event when it receives a PropertyChanged event from one
of its objects.

Each item class in the hierarchy that has a collection as one of its
properties subscribes to the ListChanged event of that collection. For all
items other than the root object of the hierarchy, the item's event handler
fires a PropertyChanged event for the collection property. The root object's
event handler does the actual processing.

This is how it works: Assume a KnowledgeBase object that contains a
Categories collection property. Each Category object in that collection
contains an Articles collection. Each Article object in that collection
contains several properties, including a Text property.

Now, let's say an Article's text is changed.

-- The Article object fires a PropertyChanged event for the Text property.

-- The Articles collection receives the event and fires a ListChanged event.

-- The Category object to which the Articles collection belongs receives
that event and fires a PropertyChanged event for the Articles property.

-- The Categories collection receives the event and fires its ListChanged
event.

-- The KnowledgeBase object receives the event and processes it.

The result is that the KnowledgeBase object is notified of any changes to
any object in the hierarchy. This behavior is very useful for setting
'IsDirty' flags and the like. Note that this solution, as written, only
works under .NET 2.0.

--
David Veeneman
Foresight Systems
Feb 12 '06 #1
1 1786
Very Cool setting, isn't this the Observer Pattern?

Feb 13 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Job Lot | last post by:
I have implemented DashStyle and LineThickness for custom circle control as follows: Public Property DashStyle() As DashStyle Get Return m_DashStyle End Get Set(ByVal Value As DashStyle)...
3
by: Stan | last post by:
Hallo, I have developed an application in MS Access 2000 (Polish version) under MS Windows XP prof (also Polish). Now I would like to run this code on MS Windows XP EN and MS Access XP EN. I have...
0
by: Filips Benoit | last post by:
A particular form - always the same - sometimes becomes corrupt after saving. Error msg = The expression On Open you entered as the event property settings produced the following error: A...
2
by: Matthew Playne | last post by:
Hi, I am having a problem communicating between to classes. I have an MDI application. The parent window contains a mainMenu and a toolbar and toolbuttons, and the child form contains a...
6
by: PaulN | last post by:
I need to instantiate a class (Class1) in the startup form (Form1), set some of Class1's properties then open another form (Form2) and have it read Class1's properties and set the remainder of...
10
by: dgk | last post by:
I'm searching for a way to determine if control values have changed. For some it's easy, such as TextBox.Modified. But looking at the radiobutton I come across IsMirrored. Curious, I look to the...
10
by: Marcin Zmyslowski | last post by:
Hello all! I have a database created in MS Access 2003 which works fine in Win2000. This database shows me the following message in WinXP: "The expression On Load you entered as the event...
9
by: lou zion | last post by:
hey all, i've got a class that A that has a static class member static int MajorMode; it's important that if one instance of the class changes this variable, all instances react...
18
by: Academia | last post by:
I let the use modify the text of a combobox and then I replace the selected item with the new text (in Keyup event). But if he sets the Text property to an empty string ("") that sets the...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.