依赖循环
1. 依赖倒置原则(Dependency Inversion Principle, DIP)
@protocol BProtocol <NSObject> - (void)doSomething; @end @interface A : NSObject @property (nonatomic, weak) id<BProtocol> delegate; @end
class ModuleA { var moduleB: ModuleB init(moduleB: ModuleB) { self.moduleB = moduleB } }
3. 中介者模式(Mediator Pattern)
4. 使用通知机制(Notification Center)
5. 委托模式(Delegate Pattern)
6. 依赖管理工具和框架
7. 弱引用解决循环依赖
8. 分层架构
9. 通过模块抽取避免循环依赖
10. 监控与测试
总结
Last updated