所以我试图使用事件来解耦我的代码,这是我的问题:
class WorldHandler
{
public void Notify(object sender, EventArgs e)
{
if (e is CameraMovedEventArgs)
{
// handle event
}
if (e is MapLoaded)
{
// handle event
}
}
}
Run Code Online (Sandbox Code Playgroud)
WorldHandler类侦听我的应用程序的不同子系统.这是不是意味着WorldHandler仍然与其他子系统耦合?直接访问这个类中的子系统不是一样的吗?
如果我很难理解我的要求,我会在帖子中添加其他信息.
我对此问题进行了研究,但我仍然觉得这很令人困惑,因为不同的人对如何将代码与事件分离有不同的看法.
c# ×1