您如何定义单一职责? [英] How do you define a Single Responsibility?

查看:67
本文介绍了您如何定义单一职责?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道班级有一个改变的唯一原因".现在,那到底是什么?是否有一些气味/迹象表明班级没有单一责任?还是真正的答案会藏在YAGNI中,而在您第一次上课时才重构为单一职责?

I know about "class having a single reason to change". Now, what is that exactly? Are there some smells/signs that could tell that class does not have a single responsibility? Or could the real answer hide in YAGNI and only refactor to a single responsibility the first time your class changes?

推荐答案

为该类所做的事情写一个简短而准确的描述.

Write a brief, but accurate description of what the class does.

如果描述中包含单词"and",则需要将其拆分.

If the description contains the word "and" then it needs to be split.

这篇关于您如何定义单一职责?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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