Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Raise event among all instances of a class

I have a abstact class named Organism which has a Born event. Also I have some classes that inherit the Organism class... So my question is how can I raise the Born event among all instances of all classes, which inherited the Organism class?

EDIT: Sorry, The event I meant to write was Tick not Born... Born is a instance level event...

like image 473
Dimitar Vouldjeff Avatar asked Dec 15 '25 20:12

Dimitar Vouldjeff


1 Answers

public class Organism : IDisposable
{
    public static List<Organism> All = new List<Organism>();

    private bool disposed = false;

    public Organism()
    {
        Organism.All.Add(this);
    }

    public void BeBorn()
    {
        throw new NotImplementedException();
    }

    public void Dispose()
    {
        Dispose(true);

        GC.SuppressFinalize(this);
    }

    private void Dispose(bool disposing)
    {
        if (!this.disposed)
        {
            if (disposing)
            {
                Organism.All.Remove(this);
            }

            disposed = true;
        }
    }

    ~Organism()
    {
        Dispose(false);
    }

}
like image 90
Jimmy Hoffa Avatar answered Dec 17 '25 09:12

Jimmy Hoffa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!