You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.1 KiB
33 lines
1.1 KiB
using System;
|
|
using System.Collections.Generic;
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
public interface IShopModelObserver<T>
|
|
{
|
|
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<T> : IDisposable
|
|
{
|
|
private List<IShopModelObserver<T>> _observers;
|
|
private IShopModelObserver<T> _observer;
|
|
|
|
internal Unsubscriber(List<IShopModelObserver<T>> observers, IShopModelObserver<T> observer)
|
|
{
|
|
this._observers = observers;
|
|
this._observer = observer;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (_observers.Contains(_observer))
|
|
_observers.Remove(_observer);
|
|
}
|
|
}
|