using System;
using System.Collections.Generic;
///
/// This interface defines an action observer. It implements a generic observer pattern and can be reused,
/// but its main usage in this project is to make the view update whenever the shop model changes.
///
public interface IShopModelObserver
{
void OnSelected(T item);
void OnRemoved(T item);
void OnAdded(T item);
void OnTransaction(int balance); // Called when a transaction happens that changes the balance of the model, contains total new balance
}
// Unsubscriber, so the observer can self-unsubscribe from this observable without any coupling
public class Unsubscriber : IDisposable
{
private List> _observers;
private IShopModelObserver _observer;
internal Unsubscriber(List> observers, IShopModelObserver observer)
{
this._observers = observers;
this._observer = observer;
}
public void Dispose()
{
if (_observers.Contains(_observer))
_observers.Remove(_observer);
}
}