首页> 外文会议>International Conference on Objects, Models, Components, Patterns >Seuss: Better Class Responsibilities through Language-Based Dependency Injection
【24h】

Seuss: Better Class Responsibilities through Language-Based Dependency Injection

机译:SEUSS:通过基于语言的依赖注入注入更好的阶级职责

获取原文
获取外文期刊封面目录资料

摘要

Unit testing is often made more difficult by the heavy use of classes as namespaces and the proliferation of static methods to encapsulate configuration code. We have analyzed the use of 120 static methods from 96 projects by categorizing them according to their responsibilities. We find that most static methods support a hodgepodge of mixed responsibilities, held together only by their common need to be globally visible. Tight coupling between instances and their classes breaks encapsulation, and, together with the global visibility of static methods, complicates testing. By making dependency injection a feature of the programming language, we can get rid of static methods altogether. We employ the following semantic changes: (1) Replace every occurrence of a global with an access to an instance variable; (2) Let that instance variable be automatically injected into the object when it is instantiated. We present Seuss, a prototype that implements this change of semantics in Smalltalk. We show how Seuss eliminates the need to use class methods for non-reflective purposes, reduces the need for creational design patterns such as Abstract Factory and simplifies configuration code, particularly for unit tests.
机译:单位测试通常通过繁重使用类作为名称空间以及封装配置代码的静态方法的扩散来实现更加困难。通过根据其职责分析,我们分析了使用96个项目的120个静态方法。我们发现,大多数静态方法支持混合责任的大杂烩,只能通过他们的常见需要全局可见。实例与其类之间的紧密耦合打破封装,以及静态方法的全局可见性,使测试复杂化。通过使依赖注入编程语言的特征,我们可以完全摆脱静态方法。我们采用以下语义更改:(1)替换对实例变量的访问的每次发生; (2)当实例化时,让该实例变量自动注入对象。我们呈现Seuss,这是一种实现Smalltalk中语义变化的原型。我们展示SEUSS如何消除使用类方法以获得非反映目的的需求,这减少了对创造性设计模式,如抽象工厂和简化配置代码,特别是对于单元测试。

著录项

相似文献

  • 外文文献
  • 中文文献
  • 专利
获取原文

客服邮箱:kefu@zhangqiaokeyan.com

京公网安备:11010802029741号 ICP备案号:京ICP备15016152号-6 六维联合信息科技 (北京) 有限公司©版权所有
  • 客服微信

  • 服务号