MVC shop project for software architecture, in Unity.
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.
 
 
 

32 lines
960 B

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);
}
// 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);
}
}