In the typical event design, you have a public event with a protected virtual event raiser. In my project, though, I have a main class that essentially functions as a manager for several other classes. Is there any reason I shouldn't set the class up like this, so that clients only have to subscribe to the manager class's event and nothing else? (Note: this is typed off-the-cuff based on my actual code, so forgive any possible minor coding errors.)
public class Manager
{
public event EventHandler<WarningEventArgs> Warning;
// Could also be internal or protected internal
// Updated based on comments below.
public void RaiseWarning(IMessageSource sender, string warning)
{
// this.Warning?.Invoke(sender, new WarningEventArgs(warning);
this.Warning?.Invoke(this, new WarningEventArgs(sender, warning);
}
}
public class Managed
{
public Managed(Manager manager)
{
this.Manager = manager;
}
public Manager Manager { get; }
public void JustSoYouKnow()
{
this.Manager.RaiseWarning(this, "Something happened you should know about.");
}
}