本文介绍了一个设计,以避免在这种情况下循环引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我们的依赖关系树:BigApp - >儿童应用 - >图书馆

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

我们所有的部件都大量使用图书馆的一个作为上述(LIBA)。
,而它需要从'更高级别的'装配班'几'公共方法和我们想避免循环引用。
你提出一个很好的设计,这是什么?

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?

推荐答案

避免这种事情的一个典型方法是通过创建不依赖于任何的接口。然后BigApp和力霸既可以依赖的接口。 BigApp可以提供具体实现的接口,然后通过该对象力霸在某些时候被使用之前。

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.

这篇关于一个设计,以避免在这种情况下循环引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 21:34
查看更多