Page
1
(This page has no text content)
Page
2
(This page has no text content)
Page
3
Praise for Just Enough Software Architecture: A Risk-Driven Approach If you’re going to read only one book on software architecture, start with this one. Just Enough Software Architecture covers the essential concepts of software architecture that everyone — programmers, developers, testers, architects, and managers — needs to know, and it provides pragmatic advice that can be put into practice within hours of reading. —Michael Keeling, professional software engineer This book reflects the author’s rare mix of deep knowledge of software architecture concepts and extensive industry experience as a developer. If you’re an architect, you will want the developers in your organization to read this book. If you’re a developer, do read it. The book is about architecture in real (not ideal) software projects. It describes a context that you’ll recognize and then it shows you how to improve your design practice in that context. —Paulo Merson, practicing software architect and Visiting Scientist at the Software Engineering Institute Fairbanks’ focus on “just enough” architecture should appeal to any developers try- ing to work out how to make the architecting process tractable. This focus is made accessible through detailed examples and advice that illustrate how an understand- ing of risk can be used to manage architecture development and scope. At the same time, Fairbanks provides detail on the more academic aspects of software architec- ture, which should help developers who are interested in understanding the broader theory and practice to apply these concepts to their projects. —Dr. Bradley Schmerl, Senior Systems Scientist, School of Computer Science, Carnegie Mellon University The Risk-Driven Model approach described in George Fairbanks’ Just Enough Software Architecture has been applied to the eXtensible Information Modeler (XIM) project here at the NASA Johnson Space Center (JSC) with much success. It is a must for all members of the project, from project management to individual developers. In fact, it is a must for every developer’s tool belt. The Code Model section and the anti-patterns alone are worth the cost of the book! —Christopher Dean, Chief Architect, XIM, Engineering Science Contract Group – NASA Johnson Space Center
Page
4
Just Enough Software Architecture will coach you in the strategic and tactical appli- cation of the tools and strategies of software architecture to your software projects. Whether you are a developer or an architect, this book is a solid foundation and reference for your architectural endeavors. —Nicholas Sherman, Program Manager, Microsoft Fairbanks synthesizes the latest thinking on process, lifecycle, architecture, modeling, and quality of service into a coherent framework that is of immediate applicability to IT applications. Fairbanks’ writing is exceptionally clear and precise while remaining engaging and highly readable. Just Enough Software Architecture is an important con- tribution to the IT application architecture literature and may well become a standard reference work for enterprise application architects. —Dr. Ian Maung, Senior VP of Enterprise Architecture at Citigroup and former Director of Enterprise Architecture at Covance This book directly tackles some key needs of software practitioners who seek that blend of tools to help them create more effective systems, more effectively. George reaches frequently into his own experience, combining important ideas from academia to provide a conceptual model, selected best practices from industry to broaden coverage, and pragmatic guidance to make software architectures that are ultimately more useful and realistic. His simple risk-based approach frames much of the book and helps calibrate what “just-enough” should be. This book is an important addition to any software architecture bookshelf. —Desmond D’Souza, Author of MAp and Catalysis, Kinetium, Inc. This book shows how software architecture helps you build software instead of dis- tracting from the job; the book lets you identify and address only those critical archi- tectural concerns that would otherwise prevent you from writing code. —Dr. Kevin Bierhoff, professional software engineer System and software developers questioning why and where about software archi- tecture will appreciate the clear arguments and enlightening analogies this book presents; developers struggling with when and how to do architecture will discover just-enough guidance, along with concepts and ideas that clarify, empower, and lib- erate. All in all, this book is easy to read, concise, yet rich with references — a well-architected and finely-designed book! —Dr. Shang-Wen Cheng, flight software engineer
Page
5
Just Enough Software Architecture A Risk-Driven Approach George Fairbanks
Page
6
Many designations used by sellers and manufacturers to distinguish their products are claimed as trademarks. In cases where Marshall & Brainerd is aware of a claim, the designations appear in initial capital or all capital letters. The author and publisher have taken care in the preparation of this book but no warranty of any kind is expressed or implied. The author and publisher assume no responsibility for errors or omissions, nor do they assume any liability for incidental or consequential damages connected with or arising out of the use of the content of this book. Published by Marshall & Brainerd 2445 7th Street Boulder, CO 80304 (303) 834-7760 Copyright © 2010 George Fairbanks All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photo- copying, recording, or otherwise, without the prior consent of the publisher. Library of Congress Control Number: 2010910450 ISBN 978-0-9846181-0-1 First printing, August 2010
Page
7
Foreword In the 1990s software architecture emerged as an explicit subfield of software engi- neering when it became widely recognized that getting the architecture right was a key enabler for creating a software-based system that met its requirements. What followed was a dizzying array of proposals for notations, tools, techniques, and pro- cesses to support architectural design and to integrate it into existing software devel- opment practices. And yet, despite the existence of this body of material, principled attention to software architecture has in many cases not found its way into common practice. Part of the reason for this has been something of a polarization of opinions about the role that architecture should play. On one side is a school of thought that advo- cates architecture-focused design, in which architecture plays a pivotal and essential role throughout the software development process. People in this camp have tended to focus on detailed and complete architectural designs, well-defined architecture milestones, and explicit standards for architecture documentation. On the other side is a school of thought that deemphasizes architecture, arguing that it will emerge naturally as a by-product of good design, or that it is not needed at all since the archi- tecture is obvious for that class of system. People in this camp have tended to focus on minimizing architectural design as an activity separate from implementation, and on reducing or eliminating architectural documentation. Clearly, neither of these camps has it right for all systems. Indeed, the central question that must be asked is “How much explicit architectural design should one carry out for a given system?” In this book, George Fairbanks proposes an answer: “Just Enough Architecture.” One’s first reaction to this might be “Well, duh!” because who would want too much or too little. But of course there is more to it than that, and it is precisely the detail- ing of principles for figuring out what “just enough” means that is the thrust of this
Page
8
vi Foreword book. As such, it provides a refreshing and non-dogmatic way to approach software architecture — one with enormous practical value. Fairbanks argues that the core criterion for determining how much architecture is enough is risk reduction. Where there is little risk in a design, little architecture is needed. But when hard system design issues arise, architecture is a tool with tremendous potential. In this way the book adopts a true engineering perspective on architecture, in the sense that it directly promotes the consideration of the costs and benefits in selecting a technique. Specifically, focusing on risk reduction aligns engi- neering benefits with costs by ensuring that architectural design is used in situations where it is likely to have the most payoff. Naturally, there are a lot of secondary questions to answer. Which risks are best addressed with software architecture? How do you apply architectural design princi- ples to resolve a design problem? What do you write down about your architectural commitments so that others know what they are? How can you help ensure that architectural commitments are respected by downstream implementers? This book answers all of these questions, and many more — making it a uniquely practical and approachable contribution to the field of software architecture. For anyone who must create innovative software systems, for anyone who is faced with tough decisions about design tradeoffs, for anyone who must find an appropriate balance between agility and discipline — in short, for almost any software engineer — this is essential reading. David Garlan Professor, School of Computer Science Director of Professional Software Engineering Programs Carnegie Mellon University May 2010
Page
9
Preface This is the book I wish I’d had when I started developing software. At the time, there were books on languages and books on object-oriented programming, but few books on design. Knowing the features of the C++ language does not mean you can design a good object-oriented system, nor does knowing the Unified Modeling Language (UML) imply you can design a good system architecture. This book is different from other books about software architecture. Here is what sets it apart: It teaches risk-driven architecting. There is no need for meticulous designs when risks are small, nor any excuse for sloppy designs when risks threaten your success. Many high-profile agile software proponents suggest that some up-front design can be helpful, and this book describes a way to do just enough architecture. It avoids the “one size fits all” process tar pit with advice on how to tune your architecture and design efforts based on the risks you face. The rigor of most techniques can be adjusted, from quick-and-dirty to meticulous. It democratizes architecture. You may have software architects at your organiza- tion — indeed, you may be one of them. Every architect I have met wishes that all developers understood architecture. They complain that developers do not under- stand why constraints exist and how seemingly small changes can affect a system’s properties. This book seeks to make architecture relevant to all software developers, not just architects. It cultivates declarative knowledge. There is a difference between being able to hit a tennis ball and knowing why you are able to hit it, what psychologists refer to as procedural knowledge versus declarative knowledge. If you are already an expert at designing and building systems then you will have employed many of the techniques
Page
10
viii Preface found here, but this book will make you more aware of what you have been doing and provide names for the concepts. That declarative knowledge will improve your ability to mentor other developers. It emphasizes the engineering. People who design and build software systems have to do many things, including dealing with schedules, resource commitments, and stakeholder needs. Many books on software architecture already cover software de- velopment processes and organizational structures. This book, in contrast, focuses on the technical parts of software development and deals with what developers do to ensure a system works — the engineering. It shows you how to build models and an- alyze architectures so that you can make principled design tradeoffs. It describes the techniques software designers use to reason about medium- to large-sized problems and points out where you can learn specialized techniques in more detail. Conse- quently, throughout this book, software engineers are referred to as developers, not differentiating architects from programmers. It provides practical advice. This book offers a practical treatment of architecture. Software architecture is a kind of software design, but design decisions influence the architecture and vice versa. What the best developers do is drill down into obstacles in detail, understand them, then pop back up to relate the nature of those obsta- cles to the architecture as a whole. The approach in this book embraces this drill- down/pop-up behavior by describing models that have various levels of abstraction, from architecture to data structure design. About me My career has been a quest to learn how to build software systems. That quest has led me to interleave academics with industrial software development. I have the complete collector’s set of computer science degrees: a BS, an MS, and a PhD (the PhD is from Carnegie Mellon University, in software engineering). For my thesis, I worked on software frameworks because they are a problem that many developers face. I developed a new kind of specification, called a design fragment, to describe how to use frameworks, and I built an Eclipse-based tool that can validate their correct usage. I was enormously fortunate to be advised by David Garlan and Bill Scherlis, and to have Jonathan Aldrich and Ralph Johnson on my committee. I appreciate academic rigor, but my roots are in industry. I have been a software developer on projects including the Nortel DMS-100 central office telephone switch, statistical analysis for a driving simulator, an IT application at Time Warner Telecom- munications, plug-ins for the Eclipse IDE, and every last stitch of code for my own web startup company. I tinker with Linux boxes as an amateur system administrator and have a closet lit by blinking lights and warmed by power supplies. I have sup-
Page
11
Preface ix ported agile techniques since their early days — in 1996 I successfully encouraged my department to switch from a six-month to a two-week development cycle, and in 1998 I started doing test-first development. Who is this book for? The primary audience for this book is practicing software developers. Readers should already know basic software development ideas — things like object-oriented soft- ware development, the UML, use cases, and design patterns. Some experience with how real software development proceeds will be exceedingly helpful, because many of this book’s basic arguments are predicated on common experiences. If you have seen developers build too much documentation or do too little thinking before cod- ing, you will know how software development can go wrong and therefore be looking for remedies like those offered in this book. This book is also suitable as a textbook in an advanced undergraduate or graduate level course. Here is what to expect depending on what kind of reader you are: Greenhorn developers or students. If you already have learned the basic me- chanics of software development, such as programming languages and data structure design, and, ideally, have taken a general software engineering class, this book will introduce you to specific models of software that will help you form a conceptual model of software architecture. This model will help you make sense of the chaos of large systems without drawing a lot of diagrams and documentation. It may give you your first taste of ideas such as quality attributes and architectural styles. You will learn how to take your understanding of small programs and ramp it up to full indus- trial scale and quality. It can accelerate your progress toward becoming an effective, experienced developer. Experienced developers. If you are good at developing systems then you will in- variably be asked to mentor others. However, you may find that you have a somewhat idiosyncratic perspective on architecture, perhaps using unique diagram notations or terminology. This book will help you improve your ability to mentor others, un- derstand why you are able to succeed where others struggle, and teach you about standard models, notations, and names. Software architects. The role of software architect can be a difficult one when others in your organization do not understand what you do and why you do it. Not only will this book teach you techniques for building systems, it will also give you ways to explain what you are doing and how you are doing it. Perhaps you will even hand this book to co-workers so that you can better work as teammates.
Page
12
x Preface Academics. This book makes several contributions to the field of software architec- ture. It introduces the risk-driven model of software architecture, which is a way of deciding how much architecture and design work to do on a project. It describes three approaches to architecture: architecture-indifferent design, architecture-focused design, and architecture hoisting. It integrates two perspectives on software architecture: the functional perspective and the quality-attribute perspective, yielding a single concep- tual model. And it introduces the idea of an architecturally-evident coding style that makes your architecture evident from reading the source code. Acknowledgments This book would not have been possible without the generous assistance of many people. Several worked closely with me on one or more chapters and deserve special recognition for their help: Kevin Bierhoff, Alan Birchenough, David Garlan, Greg Hartman, Ian Maung, Paulo Merson, Bradley Schmerl, and Morgan Stanfield. Others suffered through bad early drafts, caught huge numbers of problems, and provided needed guidance: Len Bass, Grady Booch, Christopher Dean, Michael Donohue, Daniel Dvorak, Anthony Earl, Hans Gyllstrom, Tim Halloran, Ralph Hoop, Michael Keeling, Ken LaToza, Thomas LaToza, Louis Marbel, Andy Myers, Carl Par- adis, Paul Rayner, Patrick Riley, Aamod Sane, Nicholas Sherman, Olaf Zimmermann, and Guido Zgraggen. Thank you. I would be remiss if I did not acknowledge all the people who have mentored me over the years, starting with my parents who provided more support than I can describe. My professional mentors have included Desmond D’Souza and the gang from Icon Computing; my thesis advisors, David Garlan and Bill Scherlis; and the faculty and students at Carnegie Mellon. The wonderful cover illustration was conceived and drawn by my friend Lisa Haney (http://LisaHaney.com). Alan Apt has been a source of guidance and support through the book writing process. The preparation of this book was done primarily with open source tools, including the Linux operating system, the LYX document processor, the Memoir LATEX style, the LATEX document preparation system, and the Inkscape drawing editor. Most diagrams were created using Microsoft Visio and Pavel Hruby’s Visio UML template.
Page
13
Contents Foreword v Preface vii Contents xi 1 Introduction 1 1.1 Partitioning, knowledge, and abstractions . . . . . . . . . . . . . . . 2 1.2 Three examples of software architecture . . . . . . . . . . . . . . . . 3 1.3 Reflections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.4 Perspective shift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.5 Architects architecting architectures . . . . . . . . . . . . . . . . . . . 7 1.6 Risk-driven software architecture . . . . . . . . . . . . . . . . . . . . 8 1.7 Architecture for agile developers . . . . . . . . . . . . . . . . . . . . 9 1.8 About this book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 I Risk-Driven Software Architecture 13 2 Software Architecture 15 2.1 What is software architecture? . . . . . . . . . . . . . . . . . . . . . 16 2.2 Why is software architecture important? . . . . . . . . . . . . . . . . 18 2.3 When is architecture important? . . . . . . . . . . . . . . . . . . . . 22 2.4 Presumptive architectures . . . . . . . . . . . . . . . . . . . . . . . . 23 2.5 How should software architecture be used? . . . . . . . . . . . . . . . 24 2.6 Architecture-indifferent design . . . . . . . . . . . . . . . . . . . . . 25 2.7 Architecture-focused design . . . . . . . . . . . . . . . . . . . . . . . 26
Page
14
xii CONTENTS 2.8 Architecture hoisting . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 2.9 Architecture in large organizations . . . . . . . . . . . . . . . . . . . 30 2.10 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 2.11 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 3 Risk-Driven Model 35 3.1 What is the risk-driven model? . . . . . . . . . . . . . . . . . . . . . 37 3.2 Are you risk-driven now? . . . . . . . . . . . . . . . . . . . . . . . . 38 3.3 Risks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 3.4 Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 3.5 Guidance on choosing techniques . . . . . . . . . . . . . . . . . . . . 44 3.6 When to stop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 3.7 Planned and evolutionary design . . . . . . . . . . . . . . . . . . . . 48 3.8 Software development process . . . . . . . . . . . . . . . . . . . . . 51 3.9 Understanding process variations . . . . . . . . . . . . . . . . . . . . 53 3.10 The risk-driven model and software processes . . . . . . . . . . . . . 55 3.11 Application to an agile processes . . . . . . . . . . . . . . . . . . . . 56 3.12 Risk and architecture refactoring . . . . . . . . . . . . . . . . . . . . 58 3.13 Alternatives to the risk-driven model . . . . . . . . . . . . . . . . . . 58 3.14 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 3.15 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 4 Example: Home Media Player 65 4.1 Team communication . . . . . . . . . . . . . . . . . . . . . . . . . . 67 4.2 Integration of COTS components . . . . . . . . . . . . . . . . . . . . 75 4.3 Metadata consistency . . . . . . . . . . . . . . . . . . . . . . . . . . 81 4.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 5 Modeling Advice 89 5.1 Focus on risks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 5.2 Understand your architecture . . . . . . . . . . . . . . . . . . . . . . 90 5.3 Distribute architecture skills . . . . . . . . . . . . . . . . . . . . . . . 91 5.4 Make rational architecture choices . . . . . . . . . . . . . . . . . . . 92 5.5 Avoid Big Design Up Front . . . . . . . . . . . . . . . . . . . . . . . . 93 5.6 Avoid top-down design . . . . . . . . . . . . . . . . . . . . . . . . . . 95 5.7 Remaining challenges . . . . . . . . . . . . . . . . . . . . . . . . . . 95 5.8 Features and risk: a story . . . . . . . . . . . . . . . . . . . . . . . . 97
Page
15
CONTENTS xiii II Architecture Modeling 101 6 Engineers Use Models 103 6.1 Scale and complexity require abstraction . . . . . . . . . . . . . . . . 104 6.2 Abstractions provide insight and leverage . . . . . . . . . . . . . . . . 105 6.3 Reasoning about system qualities . . . . . . . . . . . . . . . . . . . . 105 6.4 Models elide details . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 6.5 Models can amplify reasoning . . . . . . . . . . . . . . . . . . . . . . 107 6.6 Question first and model second . . . . . . . . . . . . . . . . . . . . . 108 6.7 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 6.8 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 7 Conceptual Model of Software Architecture 111 7.1 Canonical model structure . . . . . . . . . . . . . . . . . . . . . . . 114 7.2 Domain, design, and code models . . . . . . . . . . . . . . . . . . . . 115 7.3 Designation and refinement relationships . . . . . . . . . . . . . . . . 116 7.4 Views of a master model . . . . . . . . . . . . . . . . . . . . . . . . . 118 7.5 Other ways to organize models . . . . . . . . . . . . . . . . . . . . . 121 7.6 Business modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 7.7 Use of UML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 7.8 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 7.9 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 8 The Domain Model 127 8.1 How the domain relates to architecture . . . . . . . . . . . . . . . . . 128 8.2 Information model . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 8.3 Navigation and invariants . . . . . . . . . . . . . . . . . . . . . . . . 133 8.4 Snapshots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 8.5 Functionality scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . 135 8.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 8.7 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 9 The Design Model 139 9.1 Design model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 9.2 Boundary model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 9.3 Internals model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 9.4 Quality attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 9.5 Walkthrough of Yinzer design . . . . . . . . . . . . . . . . . . . . . . 143 9.6 Viewtypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 9.7 Dynamic architecture models . . . . . . . . . . . . . . . . . . . . . . 161 9.8 Architecture description languages . . . . . . . . . . . . . . . . . . . 162
Page
16
xiv CONTENTS 9.9 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 9.10 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 10 The Code Model 167 10.1 Model-code gap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 10.2 Managing consistency . . . . . . . . . . . . . . . . . . . . . . . . . . 171 10.3 Architecturally-evident coding style . . . . . . . . . . . . . . . . . . . 174 10.4 Expressing design intent in code . . . . . . . . . . . . . . . . . . . . . 175 10.5 Model-in-code principle . . . . . . . . . . . . . . . . . . . . . . . . . 177 10.6 What to express . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 10.7 Patterns for expressing design intent in code . . . . . . . . . . . . . . 180 10.8 Walkthrough of an email processing system . . . . . . . . . . . . . . 187 10.9 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 11 Encapsulation and Partitioning 195 11.1 Story at many levels . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 11.2 Hierarchy and partitioning . . . . . . . . . . . . . . . . . . . . . . . . 197 11.3 Decomposition strategies . . . . . . . . . . . . . . . . . . . . . . . . 199 11.4 Effective encapsulation . . . . . . . . . . . . . . . . . . . . . . . . . . 203 11.5 Building an encapsulated interface . . . . . . . . . . . . . . . . . . . 206 11.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 11.7 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 12 Model Elements 213 12.1 Allocation elements . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 12.2 Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 12.3 Component assemblies . . . . . . . . . . . . . . . . . . . . . . . . . . 219 12.4 Connectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 12.5 Design decisions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 12.6 Functionality scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . 234 12.7 Invariants (constraints) . . . . . . . . . . . . . . . . . . . . . . . . . 239 12.8 Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 12.9 Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 12.10 Quality attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 12.11 Quality attribute scenarios . . . . . . . . . . . . . . . . . . . . . . . . 249 12.12 Responsibilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 12.13 Tradeoffs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252 12.14 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253 13 Model Relationships 255 13.1 Projection (view) relationship . . . . . . . . . . . . . . . . . . . . . . 256
Page
17
CONTENTS xv 13.2 Partition relationship . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 13.3 Composition relationship . . . . . . . . . . . . . . . . . . . . . . . . 261 13.4 Classification relationship . . . . . . . . . . . . . . . . . . . . . . . . 261 13.5 Generalization relationship . . . . . . . . . . . . . . . . . . . . . . . 262 13.6 Designation relationship . . . . . . . . . . . . . . . . . . . . . . . . . 263 13.7 Refinement relationship . . . . . . . . . . . . . . . . . . . . . . . . . 264 13.8 Binding relationship . . . . . . . . . . . . . . . . . . . . . . . . . . . 268 13.9 Dependency relationship . . . . . . . . . . . . . . . . . . . . . . . . . 269 13.10 Using the relationships . . . . . . . . . . . . . . . . . . . . . . . . . . 269 13.11 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270 13.12 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 14 Architectural Styles 273 14.1 Advantages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274 14.2 Platonic vs. embodied styles . . . . . . . . . . . . . . . . . . . . . . . 275 14.3 Constraints and architecture-focused design . . . . . . . . . . . . . . 276 14.4 Patterns vs. styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 14.5 A catalog of styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 14.6 Layered style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 14.7 Big ball of mud style . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 14.8 Pipe-and-filter style . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 14.9 Batch-sequential style . . . . . . . . . . . . . . . . . . . . . . . . . . 283 14.10 Model-centered style . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 14.11 Publish-subscribe style . . . . . . . . . . . . . . . . . . . . . . . . . . 286 14.12 Client-server style & N-tier . . . . . . . . . . . . . . . . . . . . . . . . 288 14.13 Peer-to-peer style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290 14.14 Map-reduce style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291 14.15 Mirrored, rack, and farm styles . . . . . . . . . . . . . . . . . . . . . 293 14.16 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 14.17 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 15 Using Architecture Models 297 15.1 Desirable model traits . . . . . . . . . . . . . . . . . . . . . . . . . . 297 15.2 Working with views . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 15.3 Improving view quality . . . . . . . . . . . . . . . . . . . . . . . . . . 306 15.4 Improving diagram quality . . . . . . . . . . . . . . . . . . . . . . . . 310 15.5 Testing and proving . . . . . . . . . . . . . . . . . . . . . . . . . . . 312 15.6 Analyzing architecture models . . . . . . . . . . . . . . . . . . . . . 312 15.7 Architectural mismatch . . . . . . . . . . . . . . . . . . . . . . . . . 318 15.8 Choose your abstraction level . . . . . . . . . . . . . . . . . . . . . . 319 15.9 Planning for the user interface . . . . . . . . . . . . . . . . . . . . . . 320
Page
18
xvi CONTENTS 15.10 Prescriptive vs. descriptive models . . . . . . . . . . . . . . . . . . . 320 15.11 Modeling existing systems . . . . . . . . . . . . . . . . . . . . . . . . 320 15.12 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322 15.13 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 16 Conclusion 325 16.1 Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326 16.2 Focus on quality attributes . . . . . . . . . . . . . . . . . . . . . . . . 330 16.3 Solve problems, not just model them . . . . . . . . . . . . . . . . . . 331 16.4 Use constraints as guide rails . . . . . . . . . . . . . . . . . . . . . . 332 16.5 Use standard architectural abstractions . . . . . . . . . . . . . . . . . 333 Glossary 335 Bibliography 347 Index 355
Page
19
Chapter 1 Introduction Decade after decade, software systems have seen orders-of-magnitude increases in their size and complexity. This is remarkable — and more than a little scary for those of us who build software. In contrast, imagine how hard basketball would be if it scaled up the same way, with 5 people on the floor one decade, then 50, then 500. Because of this growth, today’s software systems are arguably the largest and most complex things ever built. Software developers are always battling the ever-stronger foes of complexity and scale, but even though their opponent grows in strength, developers have staved off defeat and even reveled in victory. How have they done this? One answer is that the increases in software size and complexity have been matched by advances in software engineering. Assembly language programming gave way to higher-level languages and structured programming. Procedures have, in many domains, given way to objects. And software reuse, which used to mean just subroutines, is now also done with extensive libraries and frameworks. It is no coincidence that the battle between developers and software complexity always seems to be at a stalemate. Since developers cannot grow bigger brains, they have instead improved their weapons. An improved weapon gives developers two options: to more easily conquer yesterday’s problems, or to combat tomorrow’s. We are no smarter than developers of the previous generation, but our improved weapons allow us to build software of greater size and complexity. Software developers wield some tangible weapons, such as Integrated Develop- ment Environments (IDEs) and programming languages, but intangible weapons ar- guably make a bigger impact. Returning to our basketball metaphor, consider a coach
Page
20
2 CHAPTER 1. INTRODUCTION and a rookie (a novice sports player) watching the same game. The coach sees more than the rookie — not because the coach’s eyes are more acute, but because he has an intangible weapon. He has built up a set of mental abstractions that allow him to convert his perceptions of raw phenomena, such as a ball being passed, into a con- densed and integrated understanding of what is happening, such as the success of an offensive strategy. The coach watches the same game that the rookie does, but he understands it better. Alan Kay has observed that your “point of view is worth 80 IQ points” (Kay, 1989). Software is similar in that there are lots of low-level details. If developers have built up a set of mental abstractions (i.e., a conceptual model), they can convert those details into a condensed understanding: where before they saw just code, perhaps they now see a thread-safe locking policy or an event-driven system. 1.1 Partitioning, knowledge, and abstractions To be successful at combating the scale and complexity of software in the next decade, developers will need improved weapons. Those weapons can be categorized, perhaps with a bit of shoehorning, into three categories: partitioning, knowledge, and abstrac- tion. Developers partition a problem so that its parts are smaller and more tractable, they apply knowledge of similar problems, and they use abstractions to help them rea- son. Partitioning, knowledge, and abstraction are effective because they enable our fixed-sized minds to comprehend an ever-growing problem. • Partitioning. Partitioning is effective as a strategy to combat complexity and scale when two conditions are true: first, the divided parts must be sufficiently small that a person can now solve them; second, it must be possible to reason about how the parts assemble1 into a whole. Parts that are encapsulated are easier to reason about, because you need to track fewer details when composing the parts into a solution. You can forget, at least temporarily, about the details inside the other parts. This allows the developer to more easily reason about how the parts will interact with each other. • Knowledge. Software developers use knowledge of prior problems to help them solve current ones. This knowledge can be implicit know-how or explicitly writ- ten down. It can be specific, as in which components work well with others, or general, as in techniques for optimizing a database table layout. It comes in many forms, including books, lectures, pattern descriptions, source code, design documents, or sketches on a whiteboard. 1Mary Shaw has remarked that when dividing and conquering, the dividing is the easy part.