I'm developing a MVVM WPF application with C# and .NET Framework 4.6.
I have this class:
public class ObservableObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChangedEvent(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
I have implemented here INotifyPropertyChanged
because I don't want to implement it in all of my ViewModel classes.
To use this class, I use inherit:
public class Presenter : ObservableObject
{
private string _someText;
public string SomeText
{
get { return _someText; }
set
{
_someText = value;
RaisePropertyChangedEvent("SomeText");
}
}
}
But, is there a way to use ObservableObject
using object composition?
I understand object composition as instead of inherit, create a private object instance of ObservableObject
in class Presenter
.
I'm not sure if any ViewModel class should implement INotifyPropertyChanged
.
UPDATE:
This is not a duplicate question. I'm asking if a ViewModel has always to implement INotifyPropertyChanged
interface or instead, I can use Object composition. I have explained before. Please, read carefully my question.