473,779 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
+ 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
INotifyProperty Changed 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 INotifyProperty Changed 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 1837
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
1422
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) m_DashStyle = Value End Set
3
23880
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 converted the mdb to version 2002 under MS Access XP Polish and under this version everything works OK. The problem starts when I copy the mdb file to Windows XP EN and start it with MS Access XP EN. I get following error: "The expression On...
0
2000
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 problem occurred while 'DB-name' was communicating with the ole server or ActiveX controle. The form has a calendar-controle. I have eliminated the code in the OnOpen-event but the form stays corrupt!
2
1439
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 richTextBox. What I am trying to do is to when a the selected text in the richTextBox is bullet indented, a menu option on the parent window is toggled on or off depending on what is
6
1054
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 Class1's properties and finally to have Form1 examine Class1 and send changes to a database. I've tried passing Class1 into a property of Form2 and every combination of Friend declaration that I can think of and can't get this to work. I'm not...
10
4170
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 help. Not very helpful. So I look to the newsgroup. Not mentioned. So now I ask. What does the IsMirrored property tell me?
10
32224
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 property setting produced the following error: A problem occured while Microsoft Access was communicating with the Ole server or ActiveX Control" I also get similiar errors On Load, On Click etc. with the same sentence
9
1358
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 immediately. while they'll all see the new value of the variable, how do you get them each to execute a function when MajorMode changes?
18
2189
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 SelectedIndex to -1. Do you have any suggestion for getting around this problem?
0
9636
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10074
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7485
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5373
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.