哪些缺点静态方法? [英] What are the downsides to static methods?

查看:130
本文介绍了哪些缺点静态方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么缺点在网站业务层与实例化一个类,然后调用类的方法用静态方法?什么是性能影响无论哪种方式?

What are the downsides to using static methods in a web site business layer versus instantiating a class and then calling a method on the class? What are the performance hits either way?

推荐答案

的性能差异将是微不足道的。

The performance differences will be negligible.

使用静态方法的缺点是,它变得越来越测试。当依赖关系是静态的方法调用pssed前$ P $,你不能替换嘲笑/存根这些依赖。如果所有的依赖关系pssed的接口,其中实现传递到组件的前$ P $,那么你可以使用该组件的模拟/存根版的单元测试,然后真正的实现(可能是迷上了IoC容器)为真正的部署。

The downside of using a static method is that it becomes less testable. When dependencies are expressed in static method calls, you can't replace those dependencies with mocks/stubs. If all dependencies are expressed as interfaces, where the implementation is passed into the component, then you can use a mock/stub version of the component for unit tests, and then the real implementation (possibly hooked up with an IoC container) for the real deployment.

这篇关于哪些缺点静态方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆