C# question about delegates interfaces

Newbie C# question. I created an interface IDominosNetMgr, and classes implementing it for different access network modes like GameCenter (iOS), or Unity multiplayer. Problem is, I have a GameManager and various other gameobjects that need to get notified when those interface methods get called. Pretty sure I need to use delegates. Is there a way to take an interface and say “this interface’s methods can also be delegate methods”? That would simplify things for me but I haven’t seen such a thing in C#. Seems like I might have to go with Events or delegate wrapper classes.

Thanks for any general advices you can think of!

An interface just specifies what the implementation should look like. If you need to be notified when interface methods are called, that would be something you would do in the code calling the methods – i.e. when you call the interface method, you also raise an event / send a message / call another message on a listener. I don’t know exactly what it is you need to achieve, but the Observer Pattern may be useful to read about.

Lauri, thanks for your reply. It turns out what I had originally created as an Interface, I just needed to convert to delegate methods and events. It seems like c# multicast delegates are exactly what the observer pattern is all about.

Here is the use case for events in C#. An event can be used to provide notifications. You can subscribe to an event if you are interested in those notifications. You can also create your own events and raise them to provide notifications when something interesting happens. The .NET Framework offers built-in types that you can use to create events. By using delegates, lambda expressions, and anonymous methods, you can create and use events in a comfortable way.

In C#, delegates form the basic building blocks for events. A delegate is a type that defines a method signature. In C++, for example, you would do this with a function pointer. In C# you can instantiate a delegate and let it point to another method. You can invoke the method through the delegate.

This post explains the implementation detail of Delegates and Events in C# .NET. You can also read my article Publish Subscribe Design Pattern In C# for more in-depth knowledge of this concept.