By having two model classes Conversation
and Message
, what are the best practices to handle the next situation: A conversation listening for its messages PropertyChanged
events and so being able to update itself.
- What are the best practices?
- How can I improve this model design?
- Is it going to generate memory leaks?
code
using SoftConsept.Collections;
public class Conversation
{
readonly SortedObservableCollection<Message> messages;
public Conversation ()
{
messages = new SortedObservableCollection<Message> ();
}
public void Add (Message message)
{
messages.Add (message);
message.PropertyChanged += HandleMessagePropertyChanged;
}
public void Remove (Message message)
{
message.PropertyChanged -= HandleMessagePropertyChanged;
messages.Remove (message);
}
public IList<Message> Messages ()
{
return messages.ToList ();
}
void HandleMessagePropertyChanged (object sender, PropertyChangedEventArgs e)
{
// Uptade omitted conversations properties using data from the updated message.
}
}
public class Message : INotifyPropertyChanged
{
}