I have one class named DataClass. This Class is responsible to saving information in database, and In this class there are some methods for saving and reading from database, Except this class I have other classes called HTMLEditor, QueryBuilder , EmailSending, InforDetails.
I need to listen to other classes by my data class , any time their information are changed then my Dataclass would be notified to save these information.
I know there is one design pattern is called observer design pattern , with this design pattern, other classes(observers) are listening to one class(subject),any time the status of subject is changed then other observers are notified.
What should I do for this problem? Is there any design pattern for this situation?
I think the interface you seek if
INotifyPropertyChanged.Microsoft Documentation: INotifyPropertyChanged
The implementation is very simple.
In every property
setyou do:And the method and events:
Every observer only need to register to that event and they get a feedback when a property changed and which one did.
As extra, some control like PropertyGrid automatically register themselves when you feed them an object that implement that interface.