You are on page 1of 503
ee ‘REREEE Me aces: Agile Software Development Principles, Patterns, and Practices POMS A Lt Se A eR ES Pn RU lets HITE AoA Re 7 ° CSG EU ie PR xia aloha fe NRE Fe tT (C= ))Robert|CAMartiny. SB Hr Fae CG EG awd AM Bk Soe Cao ey PTs et Eee ae ee es ee ee ae ey DL Clea ci ee Lee 2rd id soca Sek ee | tite Mee eet hr eo Me bd CC eee ee to ; a Oe eee i a ae ets tee Eee Ghee CeCe ae Cl z ae ets Aes Se Re bert alate ce} ae Be ae ee bs st eb sisal g Li Pp ae a Srey eatem ya eet ree Pl os.) oe Ce tae et i de en Saal ee ge ey Labbe Teele a (Designing Object-Orient C++ Applications Using the Booch Method} RRC bess a a) Languages of Program Design 3} (Addison— Tues WAC) ee ae er are oe areal tetha eg teers c Peres et tars Cie Phe Me Ae ee ee es cle zi a Cane ta belt ae rege coed ens eS Me Ree tl te) See a bs eet bo eo be ee cei ai een -02197-7 9M D7 IM per SEP TIS BIA B i oe K PEFR BIW. BR GR (#) Robert C. Martin # Mh RE aR ke F MEAS MARL OR Woe ii a PATRI PETERE GAME T ALKA Robert C. Martin 2 44H aap UIE TESE AB TL AT SE EAT TI EDR PAS IR. SANE Pot LORIE RA A. DPS T ARAYA ELIE Peed PLA DHOOM MRE < ALTE SC RCA ATRL MGR. AAI, 1 T AL LTC C4 Tava RAR OR ACIEA T U8] 609) UML FU St Sex Decne ASOT RAF 2003 EARS 13 MAKHIPRE AR, EAHA eA A: tote A APPR LURE SA A RS ES, ME PEP RR AT 27H ‘Simplified Chinese edition copyright © 2008 by PEARSON EDUCATION ASIA LIMITED and TSINGHUA UNIVERSITY PRESS. Original English language title from Proprietor’s edition of the Work, Original English language tile: Agile Software Development: Principles, Patterns, and Practices, ‘ot Edition by Robert C. Martin, Copyright © 2003 EISBN: 0-13-597444-5 All Rights Resorved. Publishes by arrangement with the original publisher, Pearson Education, Inc., publishing as, Pearson Education, Inc. This edition is authorized tor sale oniy in the People's Republic of China (exeluding the Special Administrative Region of Hong Kong and Macao), As Ssh Sc 20¢K SH BRINE oH Pearson Education #2 6C40 748 RSE MNCL TET? LURES CEL LAE. BU UEDA LER MU ET. ies ANS KU BARA OUI HAP: 01-2002-5761 AAA BMA Pearson Tducation SARA NMEA MAG MTE, HERTS. REAR cote) BUR URCATTPDL: RR). Mist eRe CR Pa AER, Be, dt Cf RE BANB I¢4:K.Zs Agile Software Development: Principles, Pattern, and Practices ISBN 7-302.07197-7 LiMo HOY Baber Daier TIk MOAN WV TPSUL 52 SUL A TO COP HAS (2003) 38 078273 PEER Pa, 2003 OME ee Piha oh NORA eee ACE hucp../faww, cup. com. en 100084 HA BL, 0106270173, RPMS, O10-62776969 STH, RB NMI. (fae na &. te Boe BD. EE RMR RE ae, 185280 AIK, 31.25 MR. 2 PM # Wk. 20035 9 AGRI 2005 4 wR KSA BB, ISBN 7-302-07197-7/ TP + $238 MH. 1~S000 BR Hh 9.00 MERA ASS AMER EY ERA BR AEARR, Boar ROMA AE, MURAL, KAA: RANE B Meat nec MAL MR e waMA xe BPAIE Ait emake Dia A A, fast esate SRBRLIA IME. JRA ARIA BA IME, Kent Beck James Grenning Robert C. Martin Mike Beedle Jim Highsmith Steve Mellor Arie van Bennekum Andrew Hunt Ken Schwaber Alistair Cockburn Ron Jeffries Jeff Sutherland Ward Cunningham Jon Kern Dave Thomas Martin Fowler Brian Marick U2 S Sa PUNE FRR: PAVE RAB RAF 0. HR RAT MEK RARE PE. BARS TPR, HWM RER. Mi R MAMEP MATER. BEART ALR, RAPA TAM URE, PAU A, RAPD BARAT ARE EDR AAR, LEAR MHRA CARA AE ALLE. SBA DAE AR 04 PRR AER AIR OR SACRA, HALE EAA IES ARLES APA SR. RAL A BOR PIL A A ES H RAGA HHARR. © LMA RGRMERL EH. RTARTA TRA, IEA. FT Rape Pp PLB AGB RET KR, BRM TRUE, FRR EMI HEME OAT DIR AT Bde IR AR A 7. RAR A RL LR A ER RAR AY, HAAR, GRAIL AT GMs AB. BRN, QAR AO A RAR LA ET BA, Weta greet Q CATA wT, SRP OcP LSP DIP IsP REP ccP CRP ADP SDP SAP OAT Rit A SRAM A-PRME, DERA—T IME EUMBA, FF ARN DARA CR. BOR BE) ART a, RATER. Liskov 38/5 2) FRB OR EBA ES INHRAD AGAR AOR LRAT OF BRT a. HORBRM KABBLEPRRECNAAMAX. HUBTEP, FATE PERAK BR. ERASER SIE RAR AA A. SAHARA Op Bt RAF Bl RE 0 RM KARST. PRY SHPO, MRAP MARAE Bom, ATH 468) RE BET, EBA SOP MAT RL RAA MSG. REM T OP HM-AK, WAKE I OP Oy PAR. FMA BOMBARD RAFF ER. BERBURRI WARARR A OTR, EMSAM 0,654 RAR Fe PARRA, ARR SFB SC Be BAM XP MARRS HARAR, LSPA, RKARES) LAT AHP. MARR TDAMAR. SBR HRRLMERHSANH, BEAR ALES ERTL A, TRUER RAMEE, ATH. GIRL, ARATE 2 ERR BP A A Ae SR AE a A. SP ait HIRE DRONE OAR EP Lk A IO RTO th Bik HAR IRIHes te He AR ARCANE, CLT MMR, ROSIER, AGRE TGA MACAU MA RG, FLOST HT HRB, TRAE AAO PSAARR GBA R, FARAH AGRE LigaeH, WDD FR AUP AAA MEAS ARAL AE, ALARA RILIR, PLS RE SL, Bait SERTCARMRECOUN, AEM AULA OT ahah ab. RATA. FR FIRE ALIA AREAL BA SEAR AIR ASAT ALL ART a BET TR AEH RA, ate Fak AAT RAE ALARA ER RRS — APR A fare FU PAAE A — 4 AR eR a PFE SHG aE BEAR AAEAT A DARA RE, HATHA SR AER RE AE ATR AAR AMPA DILEK, ALBA, OCH: PRR 2 SE AT RMR. KLRMPE. MI, RACE. HZ PERE, ET CA RH, ETHIER. SAP RR, Bat, MRP PERO ALSEM. ORT OR, BETA. AERIS, SEAL RS RO Be FER. MIRIAM AL, RANA. Tt LAT CSRS AAT UHL THAR EA. PAAR ECL, CTA AR — IB HRA AMO eS ARMM? ERT, RET ARM. PRU RR. CA TY CA PERSP TT ALA 61 AER TEAS ERAR. BET CLARA ROHR EAD UNS oe. SE, RAR TE ANH EEUE EL, BAER Te ES Hair a RSC LR Bh PRB — eR RUSE PS XTRA TALON, BIULL T PPS ARER. (THOT IRAE HOS EOI A RR GL, BURL AAR BATE, MIF LRA—— BRAS A. 50H, REHAB ED RAM. TB be 304F TT. Heh THEAS MARAT LBZ. ME, Bais, FR. AR, AE. A DSC AaB TEE. HE, RPA TAAL. BO A CE BY RAL, Ay AGRE PRACT EBA. MERRIE YER OS, PRS SUR. CREAT, ARTE. SR MAES. SECM EE RA. TARR ARI, Rela HANI: BR TTS AER ASE, SCNRAL. MLR PLASMA eT PT RA, PRATT LS SLSR, MEL ARES AO FELOIR JCP EEM IRE ARR, RATT IRT A A ht ABA BORD AS SRS, MAE HORNY RS. PELAS. (ERI. IRPPIPAA TOURER RD RESTAMAA. MEGCTAMREAT, RAGA ME LERU ERMA. ROTOR RA RAAT: AARON HAT OI RE REO. HLT tRSH. aS BP — PEAR RATER A Ll, EAMES TRORR. KR PEE AUT EHR RE. AUT SEA a AB TRE. A ee AUBIHRIL, FECORAE. SEM ASE RIA. SPARS. Hak. SEP EMD: AU. DA HORA ARISTA. HORST OSE FACIE. CESAR AEC LMS. a RP St RA BRR i>, LHR. BA BARE MID AT. RAS OIAOR EEE OE RL, PR RS ADEA ASR TPR, NAOT ESB) FTO, DRA RT OAL CRBS ATE, aA TRIN BHR Robert C, Martin 2003 £8 21 ‘The Beauty of Software Robert C. Martin's foreword for Agile Software Development Chinese Version Next to my family, software is my passion. It is a medium in which [try to create beauty. The beauty of software is in i's function, in i's internal structure, and in the way in which it is created by a team. Toa user, a program with just the right features presented through an intuitive and simple interface, is beautiful, ‘To a software designer, an intemal structure that is partitioned in a simple and intuitive manner, and that minimizes internal coupling, is beautiful, To developers and managers, a motivated team of developers ‘making significant progress every week, and producing defect-free code, is beautiful. There is beauty on all these levels, and they are all part of the topic of this book. How do software developers lear how to create this beauty? In this book I teach the principles, pattems, and practices that can help software developers take the first steps towards beautiful programs, designs, and teams. In these pages we explore basic design principle, common patterns in the structure of software design, and a set of practices that can help a team knit itself into a functioning whole. Since this ‘book is about software development, it contains a lot of code, The principles, patterns, and practices that this book teaches are Leamed most effectively by carefully studying that code. ‘Our world needs software -- lots of software, Fifly years ago software was something that ran in a few big and expensive machines. Thirty years ago it was something that ran in most companies and industrial settings. Now there is software running in our cell phones, watches, appliances, automobiles,toys, and tools. And need for new and better software never stops, As our civilization grows and expands, as developing nations build their infrastructures, as developed nations sitive to achieve ever greater efficiencies, the need for more and more software continues fo increase. It would be a great shame if, in all that software, there was no beauty. We know that software can be ugly. We know that it can be hard to use,unreliable, and carelessly structured. We know that there are software systems whose tangled and careless intemal structures make them expensive and difficult to change. We know that there are software systems that present their features through an awkward and cumbersome interface. We know that there are software systems that crash and mighehave. These ate uely systems, Unforninately, as a profession, software developers tend to create more ugly systems than beautiful ones, If you are rcading this book, then you are someone who ‘wants to create beauty and not ugliness. There is a secret that the best software developers know. Beauty is cheaper than ugliness. Beauty is faster than ugliness. A beantiful software system can be built and maintained in less time, and for less money, than an ugly one. Novice software developers don’t understand this. They think that they have to do everything fast and quick. They think that beauty is impractical. No! By doing things fast and quick, they make messes that make the software stiff, and hard (o understand. Beautiful systems are flexible and easy to understand, Building thom and maintaining them is a joy. It is ugliness that is impractical. Ugliness will slow you down and make your software expensive and brittle. Beautiful systems cost the least to build and maintain, and are detivered soonest. hope you enjoy this book. I hope you learn to take as much pride and joy in the creation of beautiful software that Ido. If this book can show you just an inkling of thet joy, motivate you to feel just the beginnings of that pride, and provide just a spark of appreciation for that beauty, then it has more thant accomplished my goal for it