问题
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