a design to avoid circular reference in this scenario

こ雲淡風輕ζ 提交于 2019-12-08 13:15:04

问题


Here is our dependency tree: BigApp -> Child Apps -> Libraries

ALL of our components are HEAVILY using one of the Libraries as above ( LibA). But it has a ‘few’ public methods that require classes from ‘higher-level’ assemblies and we want to avoid CIRCULAR references. What do you propose as a good design for this?


回答1:


One typical way of avoiding such things is by creating an interface that doesn't depend on anything. Then BigApp and LibA can both depend on the interface. BigApp can supply a concrete implementation of the interface and then pass that object to LibA at some point before it gets used.




回答2:


Depending on the specifics of your situation, you could define interfaces to abstract some of the functionality of one or more of your classes. You then reference the interfaces where you think you might induce a circular dependency.



来源:https://stackoverflow.com/questions/2724989/a-design-to-avoid-circular-reference-in-this-scenario

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!