I've been reading up on Actions and delegates for the last couple of days, and I think I'm finally starting to understand, but I wanted to check that I was using them correctly, or at least using them in a way that isn't totally insane. I'm using a text-based game (as such) as a platform for learning about what I suspect is called event-oriented programming. For a really terrible example, imagine the player has a torch that can set things on fire. I don't want the torch to do target.ChangeState(States.OnFire), that's giving the torch way too much power over other objects - nothing is preventing an action like nonFlammableRock.ChangeState(States.OnFire) I COULD have the torch tell the game manager entity that it wants to set something on fire, and then let the game manager decide if it's allowed to do so... but instead, I came up with this:TestObjectinternal class TestObject{    private string instanceVar;    private Dictionary<string, Action> eventHandlers;    public TestObject(string newInstanceVar)    {        this.instanceVar = newInstanceVar;        eventHandlers = new Dictionary<string, Action>();        eventHandlers.Add(event0, PrintInstanceVar);        eventHandlers.Add(event1, InstanceVarToUpper);        eventHandlers.Add(event2, ChangeOwnInstanceVar);    }    public void PrintInstanceVar()    {        Console.WriteLine(instanceVar);    }    public void InstanceVarToUpper()    {        instanceVar = instanceVar.ToUpper();    }    public void Event(string eventName)    {        eventHandlers[eventName].Invoke();    }    public void ChangeOwnInstanceVar()    {        instanceVar = Object has changed its instance variable;    }}Programprivate static void Main(string[] args)    {        var test1 = new TestObject(First test obejct);        test1.Event(event2);        test1.Event(event0);        test1.Event(event1);        test1.Event(event0);        Console.ReadKey();    }In short, I want to tell an object what has happened to it, and then let the object itself decide what to do. In this way, a torch can send a message ignite to any object, and the target object itself looks up ignite in its dictionary of behaviours, and reacts accordingly. So for a Rock, eventHandlers[ignite] = () => Console.WriteLine(The rock isn't flammable, the torch had no effect), whereas for HayBale, eventHandlers[ignite] = () => Console.WriteLine(The bale of hay catches alight). Is this a sane approach? Are there any traps I've missed that will come back to haunt me later? Is there a better way of doing this? I know that C# Events exist, but I don't fully understand them yet, and I don't know how to use them to achieve what I'm trying to do here - but if using Events would be better, how would I change this?Note:I know individual entities shouldn't be responsible for printing to console - if I made this whole thing, they'd be sending updates as to their state, strings containing action text etc to the game manager, which would be responsible for displaying messages for the player.
Triggering methods that change instance state on other objects using a Dictionary
c#