Why use event dispatchers vs interface when ED's need a hard reference?

We’re comparing apples to oranges. They’re not comparable. It’s not that it gets called, for the interface to deliver a message, you must explicitly send it to every instance every time you want something done.

In most situations, you will have little choice but to use one over the other because that’s the job at hand.

I also do not agree with EDs being messy, on the contrary. As soon as you add multiple interfaces, you will immediately see the clutter since every call is now available for every class even though they do not implement it.

• use an interface when you do not know the class you’re dealing with. The player walks around and Kicks stuff. We do not know what they’re going to kick. A rock? A door? A bucket? Air? A chicken? We want those entities to react but I don’t want to build a crazy deep inheritance chain since Air has nothing in commmon with a Chicken. This is a great job for an interface.

• I know precisely what happens when Chickens get the boot - so I can set it up ahead of time and then never worry about it again. When kicked, any chicken will broadcast a distress call to the 12 city guards. That’s a job for an Event Dispatcher.

The best part is that chickens and guards do not need to know about each other’s existence.

The player kicks a chicken via an interface → chicken dispatches a distress call to everyone who was told to listen.

10 Likes