Building Maintainable Software-java篇之Couple Architecture Components Loosely

Building Maintainable Software-java篇之Couple Architecture Components Loosely


There are two ways of constructing a software design: one way is to make it so simple
that there are obviously no deficiencies, and the other way is to make it so complicated
that there are no obvious deficiencies.
                           —C.A.R. Hoare



Guideline:

• Achieve loose coupling between top-level components.
• Do this by minimizing the relative amount of code within modules that is exposed to (i.e., can receive calls from) mod‐
ules in other components.
• This improves maintainability because independent components ease isolated maintenance.

Motivation

Low Component Dependence Allows for Isolated Maintenance

A low level of dependence means that changes can be made in an isolated manner.
This applies when most of a component’s code volume is either internal or outgoing.
Isolated maintenance means less work, as coding changes do not have effects outside
the functionality that you are modifying.

Low Component Dependence Separates Maintenance Responsibilities

If all components are independent from each other, it is easier to distribute responsi‐
bilities for maintenance among separate teams. This follows from the advantage of
isolated modification. Isolation is in fact a prerequisite for efficient division of devel‐
opment work among team members or among different teams.
By contrast, if components are tightly intertwined with each other, one cannot isolate
and separate maintenance responsibilities among teams, since the effects of modifica‐
tions will spill over to other teams. Aside from that code being hard to test, the effects
of modifications may also be unpredictable. So, dependencies may lead to inconsis‐
tencies, more time spent on communication between developers, and time wasted
waiting for others to complete their modifications.

Low Component Dependence Eases Testing

Code that has a low dependence on other components (modules with mainly internal
and outgoing code) is easier to test. For internal calls, functionality can be traced and
tested within the component. For outgoing calls, you do not need to mock or stub
functionality that is provided by other components (given that functionality in that
other component is finished).

How to Apply the Guideline

The following principles help you apply the guideline of this chapter:
• Limit the size of modules that are the component’s interface.
• Define component interfaces on a high level of abstraction. This limits the types
of requests that cross component borders. That avoids requests that “know too
much” about the implementation details.
• Avoid throughput code, because it has the most serious effect on testing func‐
tionality. In other words, avoid interface modules that put through calls to other
components. If throughput code exists, analyze the concerned modules in order
to solve calls that are put through to other components




Abstract Factory Design Pattern

Component independence reflects the high-level architecture of a software system.
However, this is not a book on software architecture. In this section, we discuss only
one design pattern that we frequently see applied in practice to successfully limit the
amount of interface code exposed by a component: the Abstract Factory design pat‐
tern. A system that is loosely coupled is characterized by relying more on contracts
and less on implementation details.
Many more design patterns and software architecture styles can help in keeping your
architecture components loosely coupled. An example is using a framework for
dependency injection (which allows Inversion of Control). For elaboration on other
patterns, we kindly direct you to the many great books on design patterns and soft‐
ware architecture (see, for example, “Related Books” on page xiv).


The Abstract Factory design pattern hides (or encapsulates) the creation of specific

“products” behind a generic “product factory” interface. In this context, products are

typically entities for which more than one variant exists.



读书笔记:

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
How do successful agile teams deliver bug-free, maintainable software—iteration after iteration? The answer is: By seamlessly combining development and testing. On such teams, the developers write testable code that enables them to verify it using various types of automated tests. This approach keeps regressions at bay and prevents “testing crunches”—which otherwise may occur near the end of an iteration—from ever happening. Writing testable code, however, is often difficult, because it requires knowledge and skills that cut across multiple disciplines. In Developer Testing, leading test expert and mentor Alexander Tarlinder presents concise, focused guidance for making new and legacy code far more testable. Tarlinder helps you answer questions like: When have I tested this enough? How many tests do I need to write? What should my tests verify? You’ll learn how to design for testability and utilize techniques like refactoring, dependency breaking, unit testing, data-driven testing, and test-driven development to achieve the highest possible confidence in your software. Through practical examples in Java, C#, Groovy, and Ruby, you’ll discover what works—and what doesn’t. You can quickly begin using Tarlinder’s technology-agnostic insights with most languages and toolsets while not getting buried in specialist details. The author helps you adapt your current programming style for testability, make a testing mindset “second nature,” improve your code, and enrich your day-to-day experience as a software professional. With this guide, you will Understand the discipline and vocabulary of testing from the developer’s standpoint Base developer tests on well-established testing techniques and best practices Recognize code constructs that impact testability Effectively name, organize, and execute unit tests Master the essentials of classic and “mockist-style” TDD Leverage test doubles with or without mocking frameworks Capture the benefits of programming by contract, even without runtime support for contracts Take control of dependencies between classes, components, layers, and tiers Handle combinatorial explosions of test cases, or scenarios requiring many similar tests Manage code duplication when it can’t be eliminated Actively maintain and improve your test suites Perform more advanced tests at the integration, system, and end-to-end levels Develop an understanding for how the organizational context influences quality assurance Establish well-balanced and effective testing strategies suitable for agile teams Table of Contents Chapter 1 Developer Testing Chapter 2 Testing Objectives, Styles, and Roles Chapter 3 The Testing Vocabulary Chapter 4 Testability from a Developer’s Perspective Chapter 5 Programming by Contract Chapter 6 Drivers of Testability Chapter 7 Unit Testing Chapter 8 Specification-based Testing Techniques Chapter 9 Dependencies Chapter 10 Data-driven and Combinatorial Testing Chapter 11 Almost Unit Tests Chapter 12 Test Doubles Chapter 13 Mocking Frameworks Chapter 14 Test-driven Development—Classic Style Chapter 15 Test-driven Development—Mockist Style Chapter 16 Duplication Chapter 17 Working with Test Code Chapter 18 Beyond Unit Testing Chapter 19 Test Ideas and Heuristics Appendix A: Tools and Libraries Appendix B: Source Code

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Dreamer who

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值