English 中文(简体)
应避免固定的班级,因为它使依赖性注射困难?
原标题:
  • 时间:2009-05-20 15:30:24
  •  标签:

一些负责建立一套“核心”图书馆的人设立了一套固定的班级,提供伐木、审计和共同数据库存取方法等各类公用事业。

我个人认为这种思维,因为我们现在有一套核心图书馆难以测试,因为我可以 t弄/ st住这些教室,或向建筑商投放任何注射。

我相信,我能够利用台风来阻止这些现象,但我却这样做是免费的。

你认为什么?

Edit

如果你不认为他们会重新受到考验,你可以举一个例子,说明你将如何检验他们。 这些静态的班级即刻有其他类型的工作。

最佳回答

Static classes (methods) do not necessarily have to be avoided as long as they have no hidden dependencies. Of course you can pass dependencies into a static method - it just should not be stored internally and modify the behaviour of later calls.
There should be no problem to test them in this case, too.

但我对你提到的案件也感到不好。 我知道其中一些静态“wrapper”用途类别,在大多数情况下,它们真心想:

EDIT:
Maybe I should clarify. I would use static classes/methods only for very small distinguished tasks. When static classes start to initialize dependencies they certainly should be avoided. If you can t test these static classes they already have a too big job to do.

问题回答

如何改变这些静态类别,以利用依赖性注射? 如果你使国际移民政策具有选择性(如果可能的话),你基本上可以采取这样的情况,即你可以使用固定的班级进行模拟,就像适当做国际移民政策,同时不改变任何“正常”行为。

http://www.jot.fm/issues/issue_2012_04/article3.pdf”rel=“nofollow” Journal of Object Technology: 硬性规定:

采用静态方法阻碍通过硬通电进行测试。 对开放源地小塔克法典120种固定方法的研究显示,在120种静态方法中,只有6种方法不能像实例方法一样得到实施,但并不是这样,从而给他们的呼吁人造成一种间接依赖这些静态方法的负担。





相关问题
热门标签