Skip to content

ViewModels or ObservableObjects

Marc Rousavy edited this page Aug 22, 2018 · 8 revisions

In Jellyfish one distinguishes between an observable object and a view model:

  • ObservableObject: An object that implements the INotifyPropertyChanged interface by notifying any subscribers upon property changes via the Set method
  • ViewModel: The actual ViewModel in the MVVM Pattern. A ViewModel also inherits from ObservableObject, but provides additional functionality specifically for ViewModels

Examples

View Model:

class UserViewModel : ViewModel
{
    private User _user;
    public User User
    {
        get => _user;
        set => Set(ref _user, value);
    }

    public void LoginAction()
    { ... }
}

Observable Objects:

class User : ObservableObject
{
    private string _name;
    public string Name
    {
        get => _name;
        set => Set(ref _name, value);
    }

    private DateTime _birthday;
    public DateTime Birthday
    {
        get => _birthday;
        set => Set(ref _birthday, value);
    }
}

See also: ViewModel πŸ“–, Observable Object πŸ“–

Clone this wiki locally