在“现实世界"中使用单一责任原则. [英] Using the Single Responsibility Principle in the "real world"

查看:79
本文介绍了在“现实世界"中使用单一责任原则.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上想了解一下认为在实际代码中使用单一责任原则"合理的人所占的百分比,以及实际执行的人中有多少人.在播客#38 中,乔尔谈到了OOP原理在现实世界中是多么无用的问题.并且进一步证明了像鲍勃叔叔这样的人可能没有编写非平凡的系统.

I basically want to get an idea of the percentage of people who think it's reasonable to use the Single Responsibility Principle in real-world code and how many actually do. In Podcast #38 Joel talks about how useless this OOP principle is the real world; and further that this demonstrates how people like Uncle Bob have likely not written non-trivial systems.

我曾在一些软件项目中亲自撰写或扮演过重要角色,但直到现在我的年轻职业才经历过这种模式.我喜欢这个原则,并且真的很想开始使用它.我发现播客中Joel的论点相当微弱(如果您继续在此处阅读博客评论,其他人也是如此) a>).但是,这有什么道理吗?

I've personally written or played a big role in a few software projects but have only now come across this pattern in my young career. I love the sound of this principle and would really like to start using it. I found Joel's argument in the podcast quite weak (as did others if you continue on to read the blog comments here). But, is there any truth in it?

社区对此有何看法?

推荐答案

我在应用

I have had some experience applying SOLID principles and my experience has been mainly good. I also heard the podcast and it sounds like neither Jeff nor Joel has tried any of the things they're talking about long enough to really asses the benefits. The main argument against is as usually "you write more code". If I look at what I do I write 10 maybe 20% more code (usually interface definitions) but because everything is highly decoupled it's far more maintainable. I hardly ever have situations where changes in one part of my application break other parts. So the 20% extra code i have to maintain pays for itself.

Jeff也错过了代码质量的要点.他不认为代码质量对客户有很大的好处.而且他是对的,客户不在乎.客户确实关心快速实施新功能,而这正是代码质量的源泉.我发现,保持代码质量尽可能高的投资总是会在几个月内收回投资.高质量=维护成本低.

Jeff also missed the point on code quality. He doesnt see code quality as a great benefit for the customer. And he's right, the customer doesn't care. The customer does care about having new features implemented quickly and that's where code quality comes in. I've found that the investment of keeping the quality of code as high as possible has always paid itself back within a few months. High quality = low maintenance.

我确实同意他们的观点,就像任何事情一样,您必须对这些事情保持务实.如果您需要交付某些东西,请继续并快速又肮脏地进行.但是之后请清理.

I do agree with them that like anything you have to be pragmatic about these things. If you need to deliver something then go ahead and do it fast and dirty. But clean up afterwards.

这篇关于在“现实世界"中使用单一责任原则.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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