Building Maintainable Software-java篇之Separate Concerns in Modules
  In a system that is both complex and tightly coupled, accidents are inevitable.
—Charles Perrow’s Normal Accidents
theory in one sentence

Guideline:

• Avoid large modules in order to achieve loose coupling between them.
• Do this by assigning responsibilities to separate modules and hiding implementation details behind interfaces
• This improves maintainability because changes in a loosely coupled codebase are much easier to oversee and execute than changes in a tightly coupled codebase.

Remember that the concept of a module translates to a class in object-oriented languages such as Java.

Motivation

The biggest advantage of keeping classes small is that it provides a direct path toward loose coupling between classes. Loose coupling means that your class-level design will be much more flexible to facilitate future changes. By “flexibility” we mean that you can make changes while limiting unexpected effects of those changes. Thus, loose coupling allows developers to work on isolated parts of the codebase without creating change ripples that affect the rest of the codebase. A third advantage, which cannot be underestimated, is that the codebase as a whole will be much more open to less experienced developers.

Small, Loosely Coupled Modules Allow Developers to Work on Isolated Parts of the Codebase

When a class is tightly coupled with other classes, changes to the implementation of the class tend to create ripple effects through the codebase. For example, changing the interface of a public method leads to code changes everywhere the method is called. Besides the increased development effort, this also increases the risk that class modifications lead to bugs or inconsistencies in remote parts of the codebase.

Small, Loosely Coupled Modules Ease Navigation Through the Codebase

Not only does a good separation of concerns keep the codebase flexible to facilitate future changes, it also improves the analyzability of the codebase since classes encapsulate data and implement logic to perform a single task. Just as it is easier to name methods that only do one thing, classes also become easier to name and understand when they have one responsibility. Making sure classes have only one responsibility is also known as the single responsibility principle.

Small, Loosely Coupled Modules Prevent No-Go Areas for New Developers

Classes that violate the single responsibility principle become tightly coupled and accumulate a lot of code over time. As with the UserService example in the introduction of this chapter, these classes become intimidating to less experienced developers, and
even experienced developers are hesitant to make changes to their implementation. A codebase that has a large number of classes that lack a good separation of concerns is very difficult to adapt to new requirements.

How to Apply the Guideline

In general, this guideline prescribes keeping your classes small (by addressing only one concern) and limiting the number of places where a class is called by code outside the class itself. Following are three development best practices that help to prevent tight coupling between classes in a codebase.

Split Classes to Separate Concerns

Designing classes that collectively implement functionality of a software system is the most essential step in modeling and designing object-oriented systems. In typical software projects we see that classes start out as logical entities that implement a single functionality but over time gain more responsibilities. To prevent classes from getting a large class smell, it is crucial that developers take action if a class has more than one responsibility by splitting up the class.

Hide Specialized Implementations Behind Interfaces

We can also achieve loose coupling by hiding specific and detailed implementations behind a high-level interface.

Replace Custom Code with Third-Party Libraries/Frameworks

A third situation that typically leads to tight module coupling are classes that provide generic or utility functionality. Classic examples are classes called StringUtils and FileUtils. Since these classes provide generic functionality, they are obviously called
from many places in the codebase. In many cases this is an occurrence of tight coupling that is hard to avoid. A best practice, though, is to keep the class sizes limited and to periodically review (open source) libraries and frameworks to check if they
can replace the custom implementation. Apache Commons and Google Guava are widespread libraries with frequently used utility functionality. In some cases, utility code can be replaced with new Java language features or a company-wide shared
library.

读书笔记:

Building Maintainable Software: Ten Guidelines for Future-Proof Code
by Joost Visser
Copyright © 2016 Software Improvement Group, B.V. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/
institutional sales department: 800-998-9938 or corporate@oreilly.com.
Acquisitions Editor: Rachel Roumeliotis
Editor: Nan Barber
Production Editor: Matthew Hacker
Copyeditor: Rachel Monaghan
Proofreader: Marta Justak
Indexer: WordCo Indexing Services, Inc.
Interior Designer: David Futato
Cover Designer: Randy Comer
Illustrator: Rebecca Demarest
February 2016: First Edition
Revision History for the First Edition
2016-01-25: First Release
See  http://shop.oreilly.com/product/0636920049159.do

转载于:https://www.cnblogs.com/wzjhoutai/p/7258990.html

Building Maintainable Software-java篇之Separate Concerns in Modules相关推荐

  1. Building Maintainable Software-java篇之Couple Architecture Components Loosely

    Building Maintainable Software-java篇之Couple Architecture Components Loosely There are two ways of co ...

  2. web自动化如何在不同浏览器运行_如何给树莓派搭建WEB开发运行环境之JAVA篇

    在上一篇,我们已经脱掉了她华丽的外衣,你不用再添加任何华而不实的装饰,一切都交给CLI来搞定.树莓派WEB开发运行环境之JAVA篇,只需5个步骤: 安装JAVA开发包 安装和运行maven 创建JAV ...

  3. 如何给树莓派搭建WEB开发运行环境之JAVA篇

    在上一篇,我们已经脱掉了她华丽的外衣,你不用再添加任何华而不实的装饰,一切都交给CLI来搞定.树莓派WEB开发运行环境之JAVA篇,只需5个步骤: 安装JAVA开发包 安装和运行maven 创建JAV ...

  4. map根据value值排序_凯哥带你从零学大数据系列之Java篇---第十九章:集合(Map+Collections)...

    温馨提示:如果想学扎实,一定要从头开始看凯哥的一系列文章(凯哥带你从零学大数据系列),千万不要从中间的某个部分开始看,知识前后是有很大关联,否则学习效果会打折扣. 系列文章第一篇是拥抱大数据:凯哥带你 ...

  5. BurpSuite插件开发指南之 Java 篇

    Her0in · 2016/05/27 16:53 此文接着 <BurpSuite插件开发指南之 API 下篇> .在此篇中将会介绍如何使用Java 开发 BurpSuite 的插件,重点 ...

  6. JSON总结(java篇)

    JSON总结(java篇一) JSON简介 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript的一个子集. JSON采用完全独立于 ...

  7. ios 获取一个枚举的所有值_凯哥带你从零学大数据系列之Java篇---第十一章:枚举...

    温馨提示:如果想学扎实,一定要从头开始看凯哥的一系列文章(凯哥带你从零学大数据系列),千万不要从中间的某个部分开始看,知识前后是有很大关联,否则学习效果会打折扣. 系列文章第一篇是拥抱大数据:凯哥带你 ...

  8. java私塾 java篇_Java私塾跟我学系列——JAVA篇 五、

    五:Java如何做到让机器理解我们想要做的东西 用一个图来描述这个过程会比较容易理解: 1:编写代码 首先把我们想要计算机做的事情,通过Java表达出来,写成Java文件,这个过程就是 编写代码的过程 ...

  9. 多层数组如何遍历_带你从零学大数据系列之Java篇---第五章:数组

    温馨提示:如果想学扎实,一定要从头开始看凯哥的一系列文章(凯哥带你从零学大数据系列),千万不要从中间的某个部分开始看,知识前后是有很大关联,否则学习效果会打折扣. 系列文章第一篇是拥抱大数据:凯哥带你 ...

  10. 利用动态二进制加密实现新型一句话木马之Java篇(转) 冰蝎

    概述 本系列文章重写了java..net.php三个版本的一句话木马,可以解析并执行客户端传递过来的加密二进制流,并实现了相应的客户端工具.从而一劳永逸的绕过WAF或者其他网络防火墙的检测. 本来是想 ...

最新文章

  1. 网络管理员&MCSE2003之12: 第8章 应用管理模板和审核策略
  2. 堆排序(如何手写堆)
  3. CVPR15 image retrieval reading list
  4. Kettle使用_12 CSV文件仅并发运行与复制数量
  5. CMS(Concurrent Mark-Sweep)垃圾回收器
  6. 走进异步世界:博客程序的异步化改造以及发布后的不理想情况
  7. jvm 常用调试工具和设置jvm GC方法和指令
  8. java \t怎么从头开始_通过这些简单的步骤从头开始学习Java
  9. (BFS)Meteor Shower (poj3669)
  10. android标题白色_Android设置布局背景为白色的三种方法
  11. SpringBoot | 第十四章:基于Docker的简单部署
  12. mysql创建数据库_MySQL创建数据库的两种方法
  13. 怎么关闭服务器管理器自动启动,用 systemctl 管理服务:查看状态、启动/停止服务、开启/取消开机自启动...
  14. word如何取消封面或者目录下方的页码,页码从正文开始
  15. .NET : 一定不要忘记关闭DataReader对象
  16. Python3.6笔记之腌制泡菜(pickle模块的用法)
  17. ElasticSearch分页查询的3个坑
  18. 逆序数(inverse number)
  19. 【校招VIP】IT职位校招简历千万不要用两栏的模板,另外,告诉你个陷阱:越个性机会越少
  20. 微信与支付宝扫码支付

热门文章

  1. 温度传感器的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告
  2. 画笔Paint及模拟画图工具
  3. windows7系统,ping本机ip地址请求超时的解决方案
  4. ABB机器人——设置定时检测机器人状态
  5. [SSL_CHX][2021-8-18]条件输出4
  6. 计算机rec代表什么意思,recovery是什么意思,怎么进入recovery
  7. CSS入门4 文本样式
  8. Android 仿支付宝9.0芝麻信用分效果
  9. 什么是云计算?(IaaSPaaS,SaaS区别)
  10. 计算机故障检测与维修论文的绪论,论文--汽车故障的检测与维修