473,467 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1823
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.