Utils/OwnModel.cs

41 lines
992 B
C#
Raw Permalink Normal View History

2015-11-16 00:38:57 +01:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlubbFish.Utils
{
public abstract class OwnModel<T> where T : class
{
private static readonly Lazy<T> _instance = new Lazy<T>(() => CreateInstanceOfT());
2018-09-06 22:26:38 +02:00
private readonly List<OwnView> observer = new List<OwnView>();
public static T Instance
2015-11-16 00:38:57 +01:00
{
get {
return _instance.Value;
}
}
private static T CreateInstanceOfT()
{
return Activator.CreateInstance(typeof(T), true) as T;
}
2015-11-16 00:38:57 +01:00
2017-04-16 22:55:53 +02:00
public void SetObserver(OwnView view)
{
2017-04-16 22:55:53 +02:00
this.observer.Add(view);
view.Update();
}
public void RemoveObserver(OwnView view) {
this.observer.Remove(view);
}
protected void Update()
{
2017-04-16 22:55:53 +02:00
this.observer.ForEach(delegate (OwnView view) { view.Update(); });
2015-11-16 00:38:57 +01:00
}
abstract protected void Init();
2018-09-06 22:26:38 +02:00
abstract public void Dispose();
}
2015-11-16 00:38:57 +01:00
}