Building Maintainable Software-java篇之Keep Architecture Components Balanced

Building encapsulation boundaries is a crucial skill in software architecture.

—George H. Fairbanks in Just Enough Architecture

Guideline:

? Balance the number and relative size of top-level components in your code.

? Do this by organizing source code in a way that the number of components is close to 9 (i.e., between 6 and 12) and that the
components are of approximately equal size.

? This improves maintainability because balanced components

ease locating code and allow for isolated maintenance.

A well-balanced software architecture is one with not too many and not too few components, with sizes that are approximately equal. The architecture then has a good component
balance.

An example of component imbalance would be having a few very large components that contain a disproportionate amount of  system logic and many small ones that dwindle
in comparison.

Motivation

Now we know what component balance is, but not why it is important. The reason is simple: software maintenance is easier when the software architecture
is balanced.

This section discusses in what ways you can benefit from a good system component balance: it makes it easier to find and analyze code, it better isolates effects of maintenance,
and it separates maintenance responsibilities.

A Good Component Balance Eases Finding and Analyzing Code

A clear code organization in components makes it easier to find the piece of code that

you want to change. Of course, proper code hygiene helps in this process as well, such

as using a consistent naming convention (see Chapter 11). When the number of com‐

ponents is manageable (around nine) and their volume is consistent, they allow for a

drill-down each time that you need to analyze code to modify it.

In contrast, an unbalanced organization of components is more likely to have unclear

functional boundaries. For example, a component that is very large compared to oth‐

ers is more likely to contain functionalities that are unrelated, and therefore that

component is harder to analyze.

A Good Component Balance Better Isolates MaintenanceEffects

When a system’s component balance clearly describes functional boundaries, it has a

proper separation of concerns, which makes for isolated behavior in the system. Iso‐

lated behavior within system components is relevant because it guards against unex‐

pected effects, such as regression.

More broadly, isolation of code within components has the general advantage of

modularity: components with clear functional and technical boundaries are easier to

substitute, remove, and test than components with mixed functionalities and techni‐

cal intertwinement.

Note that a good component balance in itself clearly does not guarantee isolation of

changes. After all, grouping code in different components does not necessarily make

those components independent from each other. So, the degree of dependence

between components is relevant as well, as we will discuss in Chapter 7.

A Good Component Balance Separates Maintenance Responsibilities

Having clear functional boundaries between components makes it easier to distribute

responsibilities for maintenance among separate teams. The number of components

of a system and their relative size should indicate the system’s decomposition into

functional groups.

When a system has too many or too few components, it is considered more difficult

to understand and harder to maintain. If the number of components is too low, it

does not help you much to navigate through the functionalities of the system. On the

other hand, too many components make it hard to get a clear overview of the entire

system.

How to Apply the Guideline

The two principles of component balance are:

? The number of top-level system components should ideally be 9, and generally

between 6 and 12.

? The components’ volume in terms of source code should be roughly equal.

Note that component balance is an indicator for a clear component

separation, not a goal in itself. It should follow from the system

design and development process. The division of the system into

components should be natural, not forced to nine components for

the sake of having nine components.

Decide on the Right Conceptual Level for Grouping Functionality into Components

To achieve a good system division that is easy to navigate for developers, you need to

choose the right conceptual level for grouping functionality. Usually, software systems

are organized along high-level functional domains that describe what kind of func‐

tions the system performs for the user. Alternatively, a division is made along the sep‐

arations of technical specialities.

Clarify the System’s Domains and Apply Those Consistently

Once a choice for the type of system division into components has been made, you

need to apply it consistently. An inconsistent architecture is a bad architecture.

Therefore, the division into components should be formalized and controlled. While

making the design choices may be an architect’s role, the discipline to create and

respect the component boundaries in the code organization applies to all developers.

A way to achieve this is to agree as a team in which components certain changes need

to be implemented. It is a collective responsibility to ensure that this is done in a consistent manner.

读书笔记:

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 [email protected]

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

时间: 2024-10-12 14:53:14

Building Maintainable Software-java篇之Keep Architecture Components Balanced的相关文章

Building Maintainable Software-java篇之Separate Concerns in Modules

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

Building Maintainable Software-java篇之Write Short Units of Code

Building Maintainable Software-java篇之Write Short Units of Code Any fool can write code that a computer can understand. Good programmers write code that humans can understand. -Martin Fowler Guideline: ? Limit the length of code units to 15 lines of c

Building Maintainable Software-java篇之 Write Clean Code

Building Maintainable Software-java篇之 Write Clean Code Writing clean code is what you must do in order to call yourself a professional. -Robert C. Martin Guideline: ? Write clean code. ? Do this by not leaving code smells behind after development wor

[转]有哪些值得关注的技术博客(Java篇)

有哪些值得关注的技术博客(Java篇) 大部分程序员在自学的道路上不知道走了多少坑,这个视频那个网站搞得自己晕头转向.对我个人来说我平常在学习的过程中喜欢看一些教程式的博客.这些博客的特点: 1.总结知识点相对比较全面 2.一般来说讲解知识点通俗易懂 3.路线比较清晰,不会有太多的冗余内容. 这样一来,对于自学的朋友来说,一些专业的博客不但大量的缩减了你得学习时间.提高了学习效率.更重要的是这些博客能培养你对编程的兴趣. 于是,这几期文章会主要推荐一些技术博客,目前计划打算主要分为: (已完) 

关于多线程的几个问题(面试小问题,Java篇)

面试官想考考我多线程方面的问题. 1.请说下线程与进程的关系. 答:<操作系统>中是这样说的 (1)一个线程只能属于一个进程,而一个进程可以有多个线程,但至少有一个线程.线程是操作系统可识别的最小执行和调度单位. (2)资源分配给进程,同一进程的所有线程共享该进程的所有资源.同一进程中的多个线程共享代码段(代码和常量),数据段(全局变量和静态变量),扩展段(堆存储).但是每个线程拥有自己的栈段,栈段又叫运行时段,用来存放所有局部变量和临时变量. (3)处理机分给线程,即真正在处理机上运行的是线

关于一些设计模式(面试小问题,Java篇)

今天在某公司(不透露了)写了一套Java面试题.有个题大概是这样的. Which design pattern used in Java.lang.Runtime? 就是说java.lang.Runtime里,用了什么设计模式 还有java.utils.collection里用了什么设计模式. 当时由于对这冷门知识了解的不够多,而且api也读的少,所以一时答不上来. 回到家搜了下. 答: Runtiome里 单例模式. 1)  每一个Java程序都有一个Runtime类的单一实例. 2)  通过

Tools:Installing and using the Required Tools for downloading and Building EDK II工具篇:安装/使用EDKII源码获取/

Tools:Installing and using the Required Tools for downloading and Building EDK II工具篇:安装/使用EDKII源码获取/编译工具[2.3] 2015-07   北京海淀区  张俊浩 2. Setting Up EDKII Development Environment(EDKII开发环境的搭建) ->2.1 The General Procedure Of Setting Up EDKII Development E

优秀的编程风格(Java篇)——高薪必看

今天突发奇想,对编码习惯和编程风格很感兴趣,于是乎,找了一下关于编程风格(Java篇)的资料,希望对爱好编码或者开始学习编码的同学有帮助! 来自<The Elements of Java Style>-<Java编程风格>一书,值得一读的书籍,会让你在细节上节省很多时间,合作之间更加愉快! 好处不多说了,但是有几个原则如下: 1.保持原有风格 2.坚持最小惊奇原则 3.第一次就做对 4.记录所有非规范行为 格式规范: 1.缩进嵌套的代码:在每个代码块和嵌套中加入缩进,缩进代码,加强

事件驱动模型实例详解(Java篇)

或许每个软件从业者都有从学习控制台应用程序到学习可视化编程的转变过程,控制台应用程序的优点在于可以方便的练习某个语言的语法和开发习惯(如.net和java),而可视化编程的学习又可以非常方便开发出各类人机对话界面(HMI).可视化编程或许是一个初学者开始对软件感兴趣的开始,也可能是一个软件学习的里程碑点,因为我们可以使用各类软件集成开发环境(IDE)方便的在现成的界面窗口上拖放各类组件(Component),这类组件包括我们常见的按钮(Button),单选按钮(Radio Button),复选框