中国开发网: 论坛: 程序员情感CBD: 贴子 782507
sealw: 单一职责原则
The issue in this design episode is not the fundamental complexity of the feature, which is constant, but how we divide it up. The design we chose (attaching a disconnection listener) could be argued to be more complicated than its alternative (detaching the chat within the translator). It certainly takes more lines of code, but that’s not the only metric. Instead, we’re emphasizing the “single responsibility” principle, which means each object does just one thing well and the system behavior comes from how we assemble those objects.
在这个设计阶段中的问题不是该项功能固有的复杂性(这里的复杂性是不变的),而是我们如何进行划分。可能有人认为,我们选择的设计(添加一个负责断开的监听者)比另一种方法(在翻译者中断开Chat对象)更复杂。当然代码的行数更多,但代码行不是唯一的测量指标。实际上,我们在强调“单一职责”原则,这意味着每个对象只做好一件事,而系统行为来自于这些对象的组装方式。

Sometimes this feels as if the behavior we’re looking for is always somewhere else (as Gertrude Stein said, “There is no there there”), which can be frustrating for developers not used to the style. Our experience, on the other hand, is that focused responsibilities make the code more maintainable because we don’t have to cut through unrelated functionality to get to the piece we need. See Chapter 6 for a longer discussion.
有时候这让人感觉到我们要找的行为总是在别处(像Gertrude Stein所说的那样,“那里不在那里”),这可能让不习惯这种风格的开发者感到沮丧。但根据我们的经验,专注的职责让代码的可维护性更好,因为我们不必切开不相关的功能,找到我们需要的一段代码。更多的讨论请参见第6章。

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录