public record GameEventModel;


๋ผ๋Š” record class ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค


public interface IGameEventSubscriber<T> where T : GameEventModel
{
ย  ย  public void OnNewEvent(T model);
}


๋ผ๋Š” Subscriber ๋ฅผ ๋งŒ๋“ค์–ด์„œ ์œ„ ์ด๋ฒคํŠธ๋ฅผ ๋ฐ›์Šต๋‹ˆ๋‹ค


ย  ย  private List<object> subscribers = new List<object>();

ย  ย  public void Publish<T>(T model) where T : GameEventModel
ย  ย  {
ย  ย  ย  ย  DebugConsole.Log(
ย  ย  ย  ย  ย  ย  GetType(),
ย  ย  ย  ย  ย  ย  string.Format("New event {0} // {1}", model, string.Join(", \n", subscribers)));
ย  ย  ย  ย  var channel = from subscriber in subscribers
ย  ย  ย  ย  ย  ย  where subscriber is IGameEventSubscriber<T>
ย  ย  ย  ย  ย  ย  select (IGameEventSubscriber<T>)subscriber;
ย  ย  ย  ย  foreach (var subscriber in channel.ToList())
ย  ย  ย  ย  {
ย  ย  ย  ย  ย  ย  DebugConsole.Log(
ย  ย  ย  ย  ย  ย  ย  ย  GetType(),
ย  ย  ย  ย  ย  ย  ย  ย  string.Format("New event {0} => {1}", model, subscriber));
ย  ย  ย  ย  ย  ย  subscriber.OnNewEvent(model);
ย  ย  ย  ย  }
ย  ย  }


object collection ์— ๋ชจ๋“  subscriber ๋ฅผ ๋‹ด๊ณ 

LINQ ๋กœ ํ•ด๋‹น ํƒ€์ž…์ธ์ง€ ๊ฒ€์‚ฌ ํ›„ ๋ฃจํ”„๋ฅผ ๋Œ๋ฆฝ๋‹ˆ๋‹ค


์ด ๋•Œ, ์ž„์˜์˜ ์ด๋ฒคํŠธย 


public sealed record UnitDeadEvent : GameEventModel


์„ ์ „ํŒŒํ•ด์„œ Subscriber ๊ฐ€ ๋™์ž‘ํ•˜๊ฒŒ ํ•˜๊ณ ์‹ถ์€ ๊ฒฝ์šฐ


ย  ย  public List<GameEventModel> Foo()
ย  ย  public List<UnitDeadEvent> Bob()


Foo ๋กœ ์–ป์€ collection ์˜ model ์€ ์ •์ƒ์ ์œผ๋กœ ์ „๋‹ฌ์ด ๋˜์ง€ ์•Š๊ณ 
Bob ๋กœ ์–ป์€ collection ์˜ model ์€ ์ •์ƒ์ ์œผ๋กœ ์ „๋‹ฌ์ด ๋ฉ๋‹ˆ๋‹ค

๋น„๋ก Foo ๋กœ ์–ป์€ย collection ๋‚ด ์•„์ดํ…œ๋“ค์€ GameEventModel ์ด์ง€๋งŒ, GetType ์„ ์ฐ์–ด๋ณด๋ฉด ํ™•์‹คํžˆ UnitDeadEvent ๋กœ ๋‚˜์˜ค๋Š”๋ฐ์š”.

์™œ Foo ๋Š” ์•ˆ๋˜๋Š” ๊ฒƒ์ผ๊นŒ์š”?