大量 Parent-Child 和委托模式

Massive Parent-Child and delegate pattern

我面临着一个复杂的设计问题。由于硬设计的图形,我不能将 Apple 导航模式用作 UINavigationController 或其他模式。 这是应用图

黑色箭头:协议方向 蓝色箭头:parent-child形态方向

我创建这个流程是因为我想保持单个 ViewController 内的代码清晰和隔离:我认为它们是 模块 ,它们可以在某个地方使用在其他应用程序中。 RootViewControllerMainVCs 职位经理。它决定必须显示的当前 view-controller 是哪个,并根据其状态(通过委托方法修改)对其进行配置。 单个 MainVC 不知道 RootVC 存在,它使用协议调用 Root。单个 ChildViewController 不知道它的 MainVC 存在,它使用协议等调用 Main。

代码清晰易懂,这是我的目的,但是当我必须对ChildViewControllerN、child的骨架(RootVC)进行修改时第无数 ChildViewController, child 的第无数 MainViewController, 我必须传播协议直到 RootViewController.

我的第一个问题是:这个模式正确吗?你怎么看?

我的第二个问题是:是否有一个限制点,我不必使用委托模式,而是像[=24] =]?

添加 我读了一篇关于 composite pattern 的大学讲座,它说:

A composite object knows its contained components, that is, its children. Should components maintain a reference to their parent component? Depends on application, but having these references supports the Chain of Responsibility pattern

因此,根据 Chain,我可以维护 parent 的引用,但我必须为这种引用声明一个自定义接口。但是,这样做我会减少协议的数量,但是第二个问题仍然没有答案

意见:

当我超出 parent/child 关系的单一级别时,我倾向于停止使用委托并转向 NSNotification。通常,我会 直接 NSNotification 以减少依赖性。与 KVO 相比,我更喜欢它,因为它是显式的,而随着项目的进展,KVO 更难调试。

(示例:如果在分配时刻和 KVO 交付之间在主线程上释放侦听器,后台线程上看似简单的变量分配会导致难以诊断的崩溃。)