Praise For Framework Design Guidelines - Pearsoncmg

Transcription

Praise for Framework Design Guidelines“ Framework Design Guidelines is one of those rare books that can be read at different reading levels and can be useful to different kinds of developers. Regardlessof whether you want to design an effective object model, improve your understanding of the .NET Framework, borrow from the experience of softwaregurus, stay clear of the most common programming mistakes, or just get anidea of the huge effort that led to the .NET initiative, this book is a must-read.”—Francesco Balena, The VB Migration Partner Team (www.vbmigration.com),Code Architect, Author, and Microsoft Regional Director, Italy“ Frameworks are valuable but notoriously difficult to construct: your everydecision must be geared toward making them easy to be used correctly anddifficult to be used incorrectly. This book takes you through a progression ofrecommendations that will eliminate many of those downstream ‘I wish I’dknown that earlier’ moments. I wish I’d read it earlier.”—Paul Besly, Principal Technologist, QA“ Not since Brooks’ The Mythical Man Month has the major software maker ofits time produced a book so full of relevant advice for the modern softwaredeveloper. This book has a permanent place on my bookshelf and I consult itfrequently.”—George Byrkit, Senior Software Engineer, Genomic Solutions“ Updated for the new language features of the .NET Framework 3.0 and 3.5,this book continues to be the definitive resource for .NET developers andarchitects who are designing class library frameworks. Some of the existingguidelines have been expanded with new annotations and more detail, andnew guidance covering such features as extension methods and nullabletypes has also been included. The guidance will help any developer writeclearer and more understandable code, while the annotations provide invaluable insight into some of the design decisions that made the .NET Frameworkwhat it is today.”—Scott Dorman, Microsoft MVP and President,Tampa Bay International Association of Software Architects

“ Filled with information useful to developers and architects of all levels, thisbook provides practical guidelines and expert background information toget behind the rules. Framework Design Guidelines takes the already published guidelines to a higher level, and it is needed to write applicationsthat integrate well in the .NET area.”—Cristof Falk, Software Engineer“ This book is an absolute must read for all .NET developers. It gives clear ‘do’and ‘don’t’ guidance on how to design class libraries for .NET. It also offersinsight into the design and creation of .NET that really helps developers understand the reasons why things are the way they are. This information will aiddevelopers designing their own class libraries and will also allow them to takeadvantage of the .NET class library more effectively.”—Jeffrey Richter, Author/Trainer/Consultant, Wintellect“ The second edition of Framework Design Guidelines gives you new, importantinsight into designing your own class libraries: Abrams and Cwalina franklydiscuss the challenges of adding new features to shipping versions of their products with minimal impact on existing code. You’ll find great examples of how tocreate version N 1 of your software by learning how the .NET class library teamcreated versions 2.0, 3.0, and 3.5 of the .NET library. They were able to add generics, WCF, WPF, WF, and LINQ with minimal impact on the existing APIs, evenproviding capabilities for customers wanting to use only some of the new features, while still maintaining compatibility with the original library.”—Bill Wagner, Founder and Consultant, SRT Solutions,author of Effective C# and More Effective C#“ This book is a must read for all architects and software developers thinkingabout frameworks. The book offers insight into some driving factors behindthe design of the .NET Framework. It should be considered mandatory readingfor anybody tasked with creating application frameworks.”—Peter Winkler, Sr. Software Engineer, Balance Technology Inc.

Framework Design GuidelinesSecond Edition

Microsoft .NET Development SeriesVisit informit.com /msdotnetseries for a complete list of available products.The award-winning Microsoft .NET Development Series wasestablished in 2002 to provide professional developers with themost comprehensive, practical coverage of the latest .NET technologies.Authors in this series include Microsoft architects, MVPs, and otherexperts and leaders in the field of Microsoft development technologies.Each book provides developers with the vital information and criticalinsight they need to write highly effective applications.

FrameworkDesignGuidelinesConventions, Idioms, and Patternsfor Reusable .NET LibrariesSecond EditionKrzysztof CwalinaBrad AbramsUpper Saddle River, NJ Boston Indianapolis San FranciscoNew York Toronto Montreal London Munich Paris MadridCapetown Sydney Tokyo Singapore Mexico City

Many of the designations used by manufacturersand sellers to distinguish their products are claimedas trademarks. Where those designations appear inthis book, and the publisher was aware of a trademark claim, the designations have been printedwith initial capital letters or in all capitals.The .NET logo is either a registered trademark ortrademark of Microsoft Corporation in the UnitedStates and/or other countries and is used underlicense from Microsoft.Microsoft, Windows, Visual Basic, Visual C#, andVisual C are either registered trademarks ortrademarks of Microsoft Corporation in the U.S.A.and/or other countries/regions.The authors and publisher have taken care in thepreparation of this book, but make no expressed orimplied warranty of any kind and assume noresponsibility for errors or omissions. No liability isassumed for incidental or consequential damages inconnection with or arising out of the use of the information or programs contained herein.The publisher offers excellent discounts on this bookwhen ordered in quantity for bulk purchases or special sales, which may include electronic versionsand/or custom covers and content particular to yourbusiness, training goals, marketing focus, and branding interests. For more information, please contact:U.S. Corporate and Government Sales(800) 382-3419corpsales@pearsontechgroup.comFor sales outside the United States please contact:International Salesinternational@pearson.comVisit us on the Web: informit.com/awLibrary of Congress Cataloging-in-Publication DataCwalina, Krzysztof.Framework design guidelines : conventions,idioms, and patterns for reusable .NET libraries /Krzysztof Cwalina, Brad Abrams. — 2nd ed.p. cm.Includes bibliographical references and index.ISBN 978-0-321-54561-9 (hardcover : alk. paper)1. Microsoft .NET Framework. 2. Applicationprogram interfaces (Computer software) I.Abrams, Brad. II. Title.QA76.76.M52C87 2008006.7’882—dc222008034905Copyright 2009 Microsoft CorporationAll rights reserved. Printed in the United States ofAmerica. This publication is protected by copyright, and permission must be obtained from thepublisher prior to any prohibited reproduction,storage in a retrieval system, or transmission in anyform or by any means, electronic, mechanical, photocopying, recording, or likewise. For informationregarding permissions, write to:Pearson Education, Inc.Rights and Contracts Department501 Boylston Street, Suite 900Boston, MA 02116Fax (617) 671 3447ISBN-13: 978-0-321-54561-9ISBN-10:0-321-54561-3Text printed in the United States on recycled paperat Donnelley in Crawfordsville, Indiana.Third printing, December 2009

To my wife, Ela,for her support throughout the long process of writing this book,and to my parents,Jadwiga and Janusz, for their encouragement.—Krzysztof CwalinaTo my wife, Tamara:Your love and patience strengthen me.—Brad Abrams

This page intentionally left blank

ContentsFigures xviiTables xixForeword xxiForeword to the First Edition xxiiiPreface xxvAcknowledgments xxxiAbout the Authors xxxiiiAbout the Annotators xxxv1 Introduction11.1 Q ualities of a Well-Designed Framework1.1.1 W ell-Designed Frameworks Are Simple331.1.2 W ell-Designed Frameworks Are Expensive to Design1.1.3 W ell-Designed Frameworks Are Full of Trade-Offs1.1.4 W ell-Designed Frameworks Borrow from the Past1.1.5 W ell-Designed Frameworks Are Designed to Evolve1.1.6 W ell-Designed Frameworks Are Integrated61.1.7 W ell-Designed Frameworks Are Consistent62 Framework Design Fundamentals455592.1 Progressive Frameworks 112.2  Fundamental Principles of Framework Design2.2.1 T he Principle of Scenario-Driven Design2.2.2 T he Principle of Low Barrier to Entry141521ix

xContents2.2.3 T he Principle of Self-Documenting Object Models2.2.4 T he Principle of Layered Architecture3 Naming Guidelines33373.1 Capitalization Conventions383.1.1 C apitalization Rules for Identifiers3.1.2 C apitalizing Acronyms38403.1.3 C apitalizing Compound Words and Common Terms3.1.4 C ase Sensitivity453.2 G eneral Naming Conventions3.2.1 W ord Choice46463.2.2 U sing Abbreviations and Acronyms483.2.3 A voiding Language-Specific Names493.2.4 N aming New Versions of Existing APIs3.3 Names of Assemblies and DLLs3.4 Names of Namespaces 5651543.4.1 N amespaces and Type Name Conflicts583.5 N ames of Classes, Structs, and Interfaces3.5.1 N ames of Generic Type Parameters3.5.2 N ames of Common Types3.5.3 N aming Enumerations3.6 N ames of Type Members3.6.1 N ames of Methods3.6.3 N ames of Events64646668683.6.2 N ames of Properties3.6.4 N aming Fields266870723.7 N aming Parameters 733.7.1 N aming Operator Overload Parameters3.8 N aming Resources 74744 Type Design Guidelines 774.1 Types and Namespaces794.1.1 S tandard Subnamespace Names834.2 C hoosing Between Class and Struct846043

Contents4.34.44.54.64.74.8 hoosing Between Class and InterfaceC bstract Class Design 95A Static Class Design 97 Interface Design 98 Struct Design 101 Enum Design 1034.8.1 D esigning Flag Enums1104.8.2 A dding Values to Enums1144.9 Nested Types 1154.10 Types and Assembly Metadata5 Member Design881181215.1 G eneral Member Design Guidelines5.1.1 M ember Overloading1211215.1.2 I mplementing Interface Members Explicitly5.1.3 C hoosing Between Properties and Methods5.2 P roperty Design 1385.2.1 I ndexed Property Design5.3 C onstructor Design 1445.3.1 T ype Constructor Guidelines5.4.1 C ustom Event Handler Design5.5 Field Design 1595.6 Extension Methods 1625.7 Operator Overloads 1685.7.1 Overloading Operator 1421515.4 E vent Design 1535.8 P arameter Design1321405.2.2 P roperty Change Notification Events5.7.2 C onversion Operators1281591731731755.8.1 C hoosing Between Enum and Boolean Parameters5.8.2 V alidating Arguments5.8.3 P arameter Passing1791835.8.4 M embers with Variable Number of Parameters5.8.5 P ointer Parameters190186177xi

xiiContents6 Designing for Extensibility6.1 E xtensibility Mechanisms6.1.1 U nsealed Classes1931946.1.2 P rotected Members1966.1.3 E vents and Callbacks6.1.4 V irtual Members1931972016.1.5 A bstractions (Abstract Types and Interfaces)6.2 Base Classes 2066.3 Sealing 2072037 Exceptions 2117.1 Exception Throwing 2167.2 Choosing the Right Type of Exception to Throw7.2.1 E rror Message Design7.2.2 E xception Handling2212252277.2.3 W rapping Exceptions2327.3 U sing Standard Exception Types2347.3.1 Exception and SystemException7.3.2 ApplicationException2342347.3.3 InvalidOperationException2357.3.4 A rgumentException, ArgumentNullException, andArgumentOutOfRangeException2357.3.5 N ullReferenceException, IndexOutOfRangeException, andAccessViolationException 2377.3.6 StackOverflowException7.3.7 OutOfMemoryException2372387.3.8 ComException, SEHException, and ExecutionEngine Exception 2397.4 Designing Custom Exceptions 2397.5 Exceptions and Performance 2407.5.1 T ester-Doer Pattern7.5.2 T ry-Parse Pattern241242

Contents8 Usage Guidelines2458.1 Arrays 2458.2 Attributes 2478.3 Collections 2508.3.1 C ollection Parameters2528.3.2 C ollection Properties and Return Values2538.3.3 C hoosing Between Arrays and Collections8.3.4 I mplementing Custom Collections8.48.58.68.78.88.9258259DateTime and DateTimeOffset 261 Cloneable 263IIComparable T and IEquatable T IDisposable 266 Nullable T 266 Object 2688.9.1 O bject.Equals2688.9.2 O bject.GetHashCode8.9.3 O bject.ToString8.10 S erialization2642702712748.10.1 Choosing the Right Serialization Technology to Support8.10.2 S upporting Data Contract Serialization8.10.3 S upporting XML Serialization2762808.10.4 S upporting Runtime Serialization2818.11 Uri 2838.11.1 System.Uri Implementation Guidelines2848.12 S ystem.Xml Usage 2848.13 Equality Operators 2868.13.1 E quality Operators on Value Types2878.13.2 E quality Operators on Reference Types9 Common Design Patterns 2899.1 A ggregate Components2899.1.1 C omponent-Oriented Design9.1.2 F actored Types2912949.1.3 A ggregate Component Guidelines295287275xiii

xivContents9.2 T he Async Patterns2989.2.1 C hoosing Between the Async Patterns9.2.2 C lassic Async Pattern2983009.2.3 C lassic Async Pattern Basic Implementation Example9.2.4 E vent-Based Async Pattern3059.2.5 S upporting Out and Ref Parameters9.2.6 S upporting Cancellation3089.2.7 S upporting Progress Reporting3099.2.8 S upporting Incremental Results9.3 D ependency Properties3073113129.3.1 D ependency Property Design3139.3.2 A ttached Dependency Property Design9.3.3 D ependency Property Validation3153169.3.4 D ependency Property Change Notifications9.3.5 D ependency Property Value Coercion9.4 D ispose Pattern3173183199.4.1 B asic Dispose Pattern9.4.2 F inalizable Types9.5 Factories 3329.6 LINQ Support 3379.6.1 O verview of LINQ3223283379.6.2 W ays of Implementing LINQ Support3399.6.3 S upporting LINQ through IEnumerable T 9.6.4 S upporting LINQ through IQueryable T 9.6.5 S upporting LINQ through the Query Pattern9.7 Optional Feature Pattern 3449.8 Simulating Covariance 3489.9 Template Method 3549.10 Timeouts 3569.11 XAML Readable Types 3589.12 And in the End. 361A C# Coding Style Conventions 363A.1 G eneral Style ConventionsA.1.1 B race Usage364A.1.2 S pace Usage365364339340341304

ContentsA.1.3 I ndent UsageA.1.4 O ther367367A.2 Naming Conventions 367A.3 Comments 368A.4 File Organization 369B Using FxCop to Enforce the Framework Design GuidelinesB.1B.2B.3B.4 hat Is FxCop? 371W he Evolution of FxCop 372T ow Does It Work? 373H FxCop Guideline Coverage 374B.4.1 F xCop Rules for the Naming Guidelines374B.4.2 F xCop Rules for the Type Design GuidelinesB.4.3 F xCop Rules for Member DesignB.4.4 F xCop Rules for Designing for ExtensibilityB.4.5 F xCop Rules for Exceptions395B.4.6 F xCop Rules for Usage GuidelinesB.4.7 F xCop Rules for Design PatternsC Sample API Specification 405Glossary 413Suggested Reading ListIndex 423419384387397402394371xv

This page intentionally left blank

FiguresFigure 2-1: Learning curve of a multiframework platform12Figure 2-2: Learning curve of a progressive framework platformFigure 4-1: The logical grouping of types1377Figure 9-1: Query Pattern Method Signatures341xvii

This page intentionally left blank

Tables5BCMF Capitalization Rules for Different Types of Identifiers5BCMF Capitalization and Spelling for Common CompoundWords and Common Terms435BCMF CLR Type Names for Language-Specific Type Names5BCMF Name Rules for Types Derived from or ImplementingCertain Core Types5BCMF 5065Operators and Corresponding Method Names5BCMF .NET Framework Serialization Technologies1722745BCMF # Suffixes for Common Base Types and Interfaces5BCMF # Symmetric Operators403793925BCMF # Exceptions to Avoid Throwing396YJY

This page intentionally left blank

ForewordWhen the .NET Framework was first published, I was fascinated by thetechnology. The benefits of the CLR (Common Language Runtime), itsextensive APIs, and the C# language were immediately obvious. Butunderneath all the technology were a common design for the APIs and aset of conventions that were used everywhere. This was the .NET culture.Once you had learned a part of it, it was easy to translate this knowledgeinto other areas of the Framework.For the past 16 years, I have been working on open source software.Since contributors span not only multiple backgrounds but multiple years,adhering to the same style and coding conventions has always been veryimportant. Maintainers routinely rewrite or adapt contributions to software to ensure that code adheres to project coding standards and style. Itis always better when contributors and people who join a software projectfollow conventions used in an existing project. The more information thatcan be conveyed through practices and standards, the simpler it becomesfor future contributors to get up-to-speed on a project. This helps the project converge code, both old and new.As both the .NET Framework and its developer community havegrown, new practices, patterns, and conventions have been identified.Brad and Krzysztof have become the curators who turned all of this newknowledge into the present-day guidelines. They typically blog about anew convention, solicit feedback from the community, and keep track ofxxi

xxiiForewordthese guidelines. In my opinion, their blogs are must-read documentsfor everyone who is interested in getting the most out of the .NETFramework.The first edition of Framework Design Guidelines became an instant classic in the Mono community for two valuable reasons. First, it provided usa means of understanding why and how the various .NET APIs had beenimplemented. Second, we appreciated it for its invaluable guidelines thatwe too strived to follow in our own programs and libraries. This new edition not only builds on the success of the first but has been updated withnew lessons that have since been learned. The annotations to the guidelines are provided by some of the lead .NET architects and great programmers who have helped shape these conventions.In conclusion, this text goes beyond guidelines. It is a book that youwill cherish as the “classic” that helped you become a better programmer,and there are only a select few of those in our industry.Miguel de IcazaBoston, MA

Foreword to the First EditionIn the early days of development of the .NET Framework, before it waseven called that, I spent countless hours with members of the development teams reviewing designs to ensure that the final result would be acoherent platform. I have always felt that a key characteristic of a framework must be consistency. Once you understand one piece of the framework, the other pieces should be immediately familiar.As you might expect from a large team of smart people, we had manydifferences of opinion—there is nothing like coding conventions to sparklively and heated debates. However, in the name of consistency, we gradually worked out our differences and codified the result into a commonset of guidelines that allow programmers to understand and use theFramework easily.Brad Abrams, and later Krzysztof Cwalina, helped capture theseguidelines in a living document that has been continuously updated andrefined during the past six years. The book you are holding is the result oftheir work.The guidelines have served us well through three versions of the .NETFramework and numerous smaller projects, and they are guiding thedevelopment of the next generation of APIs for the Microsoft Windowsoperating system.xxiii

xxivForeword to the First EditionWith this book, I hope and expect that you will also be successful inmaking your frameworks, class libraries, and components easy to understand and use.Good luck and happy designing.Anders HejlsbergRedmond, WAJune 2005

PrefaceThis book, Framework Design Guidelines, presents best practices for designing frameworks, which are reusable object-oriented libraries. The guidelines are applicable to frameworks in various sizes and scales of reuse,including the following: Large system frameworks, such as the .NET Framework, usuallyconsisting of thousands of types and used by millions of developers. Medium-size reusable layers of large distributed applications orextensions to system frameworks, such as the Web ServicesEnhancements. Small components shared among several applications, such as a gridcontrol library.It is worth noting that this book focuses on design issues that directlyaffect the programmability of a framework (publicly accessible APIs1). Asa result, we generally do not cover much in terms of implementationdetails. Just as a user interface design book doesn’t cover the details ofhow to implement hit testing, this book does not describe how to implement a binary sort, for example. This scope allows us to provide a definitiveguide for framework designers instead of being yet another book aboutprogramming.1. This includes public types, and their public, protected, and explicitly implemented members of these types.xxv

xxviPrefaceThese guidelines were created in the early days of .NET Frameworkdevelopment. They started as a small set of naming and design conventions but have been enhanced, scrutinized, and refined to a point wherethey are generally considered the canonical way to design frameworks atMicrosoft. They carry the experience and cumulative wisdom of thousandsof developer hours over three versions of the .NET Framework. We triedto avoid basing the text purely on some idealistic design philosophies, andwe think its day-to-day use by development teams at Microsoft has madeit an intensely pragmatic book.The book contains many annotations that explain trade-offs, explainhistory, amplify, or provide critiquing views on the guidelines. These annotations are written by experienced framework designers, industry experts,and users. They are the stories from the trenches that add color and settingfor many of the guidelines presented.To make them more easily distinguished in text, namespace names,classes, interfaces, methods, properties, and types are set in monospace font.The book assumes basic familiarity with .NET Framework programming. A few guidelines assume familiarity with features introduced inversion 3.5 of the Framework. If you are looking for a good introduction toFramework programming, there are some excellent suggestions in theSuggested Reading List at the end of the book.Guideline PresentationThe guidelines are organized as simple recommendations using Do, Consider, Avoid, and Do not. Each guideline describes either a good orbad practice, and all have a consistent presentation. Good practices havea 3 in front of them, and bad practices have an 7 in front of them. Thewording of each guideline also indicates how strong the recommendationis. For example, a Do guideline is one that should always2 be followed (allexamples are from this book):2. Always might be a bit too strong a word. There are guidelines that should literally be alwaysfollowed, but they are extremely rare. On the other hand, you probably need to have areally unusual case for breaking a Do guideline and still have it be beneficial to the users ofthe framework.

Preface3 DO name custom attribute classes with the suffix “Attribute.”public class ObsoleteAttribute : Attribute { . }On the other hand, Consider guidelines should generally be followed,but if you fully understand the reasoning behind a guideline and have agood reason to not follow it anyway, you should not feel bad about breaking the rules:3 CONSIDER defining a struct instead of a class if instances of the type aresmall and commonly short-lived or are commonly embedded in otherobjects.Similarly, Do not guidelines indicate something you should almostnever do:7DO NOT assign instances of mutable types to read-only fields.Less strong, Avoid guidelines indicate that something is generally not agood idea, but there are known cases where breaking the rule makes sense:7AVOID using ICollection T or ICollection as a parameter just toaccess the Count property.Some more complex guidelines are followed by additional backgroundinformation, illustrative code samples, and rationale:3 DO implement IEquatable T on value types.The Object.Equals method on value types causes boxing and its defaultimplementation is not very efficient because it uses reflection.IEquatable T .Equals can offer much better performance and can beimplemented so it does not cause boxing.public struct Int32 : IEquatable Int32 {public bool Equals(Int32 other){ . }}xxvii

xxviiiPrefaceLanguage Choice and Code ExamplesOne of the goals of the Common Language Runtime (CLR) is to support avariety of programming languages: those with implementations providedby Microsoft, such as C , VB, C#, F#, Python, and Ruby, as well as thirdparty languages such as Eiffel, COBOL, Fortran, and others. Therefore, thisbook was written to be applicable to a broad set of languages that can beused to develop and consume modern frameworks.To reinforce the message of multilanguage framework design, we considered writing code examples using several different programming languages. However, we decided against this. We felt that using differentlanguages would help to carry the philosophical message, but it couldforce readers to learn several new languages, which is not the objective ofthis book.We decided to choose a single language that is most likely to be readable to the broadest range of developers. We picked C#, because it is asimple language from the C family of languages (C, C , Java, and C#), afamily with a rich history in framework development.Choice of language is close to the hearts of many developers, and weoffer apologies to those who are uncomfortable with our choice.About This BookThis book offers guidelines for framework design from the top down.Chapter 1, “Introduction,” is a brief orientation to the book, describingthe general philosophy of framework design. This is the only chapter without guidelines.Chapter 2, “Framework Design Fundamentals,” offers principles andguidelines that are fundamental to overall framework design.Chapter 3, “Naming Guidelines,” contains common design idioms andnaming guidelines for various parts of a framework, such as namespaces,types, and members.Chapter 4, “Type Design Guidelines,” provides guidelines for the general design of types.

PrefaceChapter 5, “Member Design,” takes a further step and presents guidelines for the design of members of types.Chapter 6, “Designing for Extensibility,” presents issues and guidelinesthat are important to ensure appropriate extensibility in your framework.Chapter 7, “Exceptions,” presents guidelines for working with exceptions, the preferred error reporting mechanisms.Chapter 8, “Usage Guidelines,” contains guidelines for extending andusing types that commonly appear in frameworks.Chapter 9, “Common Design Patterns,” offers guidelines and examplesof common framework design patterns.Appendix A, “C# Coding Style Conventions,” contains a short description of coding conventions used in this book.Appendix B, “Using FxCop to Enforce the Framework Design Guidelines,” describes a tool called FxCop. The tool can be used to analyze framework binaries for compliance with the guidelines described in this book. Alink to the tool is included on the DVD that accompanies this book.Appendix C, “Sample API Specification,” is a sample of an API specification that framework designers within Microsoft create when designing APIs.Included with the book is a DVD that contains several hours of videopresentations covering topics presented in this book by the authors, a sample API specification, and other useful resources.xxix

This page intentionally left blank

AcknowledgmentsThis book, by its nature, is the collected wisdom of many hundreds of people, and we are deeply grateful to all of them.Many people within Microsoft have worked long and hard, over aperiod of years, proposing, debating, and finally, writing many of theseguidelines. Although it is impossible to name everyone who has beeninvolved, a few deserve special mention: Chris Anderson, Erik Christensen,Jason Clark, Joe Duffy, Patrick Dussud, Anders Hejlsberg, Jim Miller,Michael Murray, Lance Olson, Eric Gunnerson, Dare Obasanjo, SteveStarck, Kit George, Mike Hillberg, Greg Schecter, Mark Boulter, Asad Jawahar, Justin Van Patten, and Mircea Trofin.We’d also like to thank the annotators: Mark Alcazar, Chris Anderson,Christopher Brumme, Pablo Castro, Jason Clark, Steven Clarke, Joe Duffy, Patrick Dussud, Mike Fanning, Kit George, Jan Gray, Brian Grunkemeyer,Eric Gunnerson, Phil Haack, Anders Hejlsberg, David Kean, Rico Mariani,Anthony Moore, Vance Morrison, Christophe Nasarre, Dare Obasanjo,Brian Pepin, Jon Pincus, Jeff Prosise, Brent Rector, Jeffrey Richter, GregSchechter, Chris Sells, Steve Starck, Herb Sutter, Clemens Szyperski, MirceaTrofin, and Paul Vick.Their insights provide much needed commentary, color, humor, andhistory that add tremendous value to this book.Sheridan Harrison and David Kean actually wrote and edited Appendix B on FxCop, which would not have been done without theirskill and passion for this tool.xxxi

xxxiiAcknowledgmentsFor all of the help, reviews, and support, both technical and moral, wethank Martin Heller. And for their insightful and helpful comments, weappreciate Pierre Nallet, George Byrkit, Khristof Falk, Paul Besley, Bill Wagner, and Peter Winkler.We would also like to give special thanks to Susann Ragsdale, whoturned this book from a semi-random collection of disconnected thoughtsinto seamlessly flowing prose. Her flawless writing, patience, and fabuloussense of humor made the process of writing this book so much easier.

About the AuthorsBrad Abrams was a founding member of the Common Language Runtime and .NET Framework teams at Microsoft Corporation. He has beendesigning parts of the .NET Framework since 1998 and is curre

Contents xi 4.3 Choosing Between Class and Interface 88 4.4 Abstract Class Design 95 4.5 Static Class Design 97 4.6 Interface Design 98 4.7 Struct Design 101 4.8 Enum Design 103 4.8.1 Designing Flag Enums 110 4.8.2 Adding Values to Enums 114 4.9 Nested Types 115 4.10 Types and Assembly Metadata 118 5 Member Design 121 5.1 General Member Design Guidelines 121