Framework Design Guidelines

Similar documents
Quality Code. Software Testing Principles, Practices, and Patterns. Stephen Vance. AAddison-Wesley

PYTHON. p ykos vtawynivis. Second eciitiovl. CO Ve, WESLEY J. CHUN

Programming in Python 3

The Unified Modeling Language User Guide

Framework Design Guidelines Conventions Idioms And Patterns For Reusable Net Libraries

MariaDB Crash Course. A Addison-Wesley. Ben Forta. Upper Saddle River, NJ Boston. Indianapolis. Singapore Mexico City. Cape Town Sydney.

Cloud Computing and SOA Convergence in Your Enterprise

Fit for Developing Software

Rails AntiPatterns. Chad Pytel. Best Practice Ruby on Rails Refactoring. Tammer Saleh. AAddison-Wesley

Refactoring HTML. Improving the Design of Existing Web Applications. Elliotte Rusty Harold. TT rvaddison-wesley

\ Smart Client 0" Deploymentwith v^ ClickOnce

ECLIPSE RICH CLIENT PLATFORM

JAVASCRIPT FOR PROGRAMMERS

Programming. Principles and Practice Using C++ Bjarne Stroustrup. / Addison-Wesley. Second Edition

ony Gaddis Haywood Community College STARTING OUT WITH PEARSON Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto

Programming. In Ada JOHN BARNES TT ADDISON-WESLEY

Application Programming

IPHONE FOR PROGRAMMERS: AN APP-DRIVEN APPROACH

Visual C# Tony Gaddis. Haywood Community College STARTING OUT WITH. Piyali Sengupta. Third Edition. Global Edition contributions by.

Domain-Specific. Languages. Martin Fowler. AAddison-Wesley. Sydney Tokyo. With Rebecca Parsons

Modern C++ Design. Generic Programming and Design Patterns Applied. Andrei Alexandrescu

Essentials. Oracle Solaris Cluster. Tim Read. Upper Saddle River, NJ Boston Indianapolis San Francisco. Capetown Sydney Tokyo Singapore Mexico City

Modern C++ Design. Generic Programming and Design Patterns Applied. Andrei Alexandrescu. AAddison-Wesley

Modern C++ Design. Generic Programming and Design Patterns Applied. Andrei Alexandrescu. .~Addison-Wesley

Digital System Design with SystemVerilog

Programming Wireless Devices with the Java 2 Platform, Micro Edition

The Power of Events. An Introduction to Complex Event Processing in Distributed Enterprise Systems. David Luckham

SQL Queries. for. Mere Mortals. Third Edition. A Hands-On Guide to Data Manipulation in SQL. John L. Viescas Michael J. Hernandez

Secure Coding in C and C++

LATEX. Leslie Lamport. Digital Equipment Corporation. Illustrations by Duane Bibby. v ADDISON-WESLEY

World Wide Web PROGRAMMING THE PEARSON EIGHTH EDITION. University of Colorado at Colorado Springs

Core Java Volume Ii Advanced Features 10th Edition

Programming Guide. Aaftab Munshi Dan Ginsburg Dave Shreiner. TT r^addison-wesley

Database Concepts. David M. Kroenke UNIVERSITATSBIBLIOTHEK HANNOVER

Business Driven Data Communications

Essentials of Database Management

Developer's HTML5. Cookbook. AAddison-Wesley. Chuck Hudson. Tom Leadbetter. Upper Saddle River, NJ Boston Indianapolis San Francisco

The Java Tutorial. A Short Course on the Basics. Raymond Gallardo. Sowmya Kannan. AAddison-Wesley. Sharon Biocca Zakhour.

CLASSIC DATA STRUCTURES IN JAVA

Virtualization from the Trenches

ECLIPSE MODELING PROJECT

A Document Preparation System. User's Guide and Reference Manual. Leslie Lamport

DB2 SQL Tuning Tips for z/os Developers

THE AVR MICROCONTROLLER AND EMBEDDED SYSTEMS. Using Assembly and С

Agile Principles, Patterns, and Practices in C#

DATA ABSTRACTION AND PROBLEM SOLVING WITH JAVA

Xcode 6 Start to Finish

Elements Of Programming Interviews In Python The Insiders Guide

Fundamentals of. Database Systems. Shamkant B. Navathe. College of Computing Georgia Institute of Technology PEARSON.

C++ Primer, Fifth Edition

Microsoft Visual C# Step by Step. John Sharp

Opengl Programming On Mac Os X Architecture Performance

FUNDAMENTALS OF. Database S wctpmc. Shamkant B. Navathe College of Computing Georgia Institute of Technology. Addison-Wesley

Microsoft. Microsoft Visual C# Step by Step. John Sharp

Prelude to Programming

Eclipse Plug-ins. Third Edition

Real-Time Systems and Programming Languages

Programming with POSIX Threads

Effective Stl 50 Specific Ways To Improve Your Use Of The... Effective Stl: 50 Specific Ways To Improve The Use Of The...

Objects First with Java

Clean Code. A Handbook of Agile Software Craftsmanship. The Object Mentors: Robert С Martin

Access ComprehGnsiwG. Shelley Gaskin, Carolyn McLellan, and. Nancy Graviett. with Microsoft

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

OpenGL SUPERBIBLE. Fifth Edition. Comprehensive Tutorial and Reference. Richard S. Wright, Jr. Nicholas Haemel Graham Sellers Benjamin Lipchak

C# Programming: From Problem Analysis to Program Design. Fourth Edition

Expert C++/CLI:.NET for Visual C++ Programmers

Systems:;-'./'--'.; r. Ramez Elmasri Department of Computer Science and Engineering The University of Texas at Arlington

Microsoft Visual Studio 2010

OpenGL. Shading Language. Third Edition

Eclipse Building Commercial-Quality Plug-ins Second Edition

Data Structures and Abstractions with Java

CJT^jL rafting Cm ompiler

Elements Of Programming Interviews In Java The Insiders Guide

Anany Levitin 3RD EDITION. Arup Kumar Bhattacharjee. mmmmm Analysis of Algorithms. Soumen Mukherjee. Introduction to TllG DCSISFI &

Embedded Systems Architecture

Programming C# 5.0. Ian Griffiths O'REILLY' Beijing Cambridge * Farnham Kbln Sebastopol Tokyo

C++ (Non for C Programmer) (BT307) 40 Hours

Computers as Components Principles of Embedded Computing System Design

Search Engines Information Retrieval in Practice

DATABASE SYSTEM CONCEPTS

Integrated Approach. Operating Systems COMPUTER SYSTEMS. LEAHY, Jr. Georgia Institute of Technology. Umakishore RAMACHANDRAN. William D.

C# 6.0 in a nutshell / Joseph Albahari & Ben Albahari. 6th ed. Beijin [etc.], cop Spis treści

Complete. The. Reference. Christopher Adamson. Mc Grauu. LlLIJBB. New York Chicago. San Francisco Lisbon London Madrid Mexico City

PROBLEM SOLVING USING JAVA WITH DATA STRUCTURES. A Multimedia Approach. Mark Guzdial and Barbara Ericson PEARSON. College of Computing

Network Programming With Go Essential Skills For Using And Securing Networks

Coding for Penetration

Whom Is This Book For?... xxiv How Is This Book Organized?... xxiv Additional Resources... xxvi

Essential Check Point FireWall-1

CCNA Cisco Certified Network Associate Study Guide

Practical C++ Programming

Beginning ASP.NET. 4.5 in C# Matthew MacDonald

^l^s^^^^^^^^^^s^^^ ^.1^L^ gs *^gs (s^s^^^^s^^ ^S^^^^ls

Embedded Linux Primer, Second Edition

Python The Definitive Guide To Learning Python Programming

C # Coding Standards for.net By Lance Hunt. Document Version 1.13 August Copyright Lance Hunt 2004 All Rights Reserved

Introduction to C++/CLI 3. What C++/CLI can do for you 6 The rationale behind the new syntax Hello World in C++/CLI 13

An Introduction to Object-Oriented Programming

C # Coding Standards for.net By Lance Hunt. Document Version 1.13a August Copyright Lance Hunt 2004 All Rights Reserved

PeopleSoft PeopleTools Tips & Techniques

The Definitive Guide to the ARM Cortex-M3

Transcription:

Framework Design Guidelines Conventions, Idioms, and Patterns for Reusable.NET Libraries Krzysztof Cwalina Brad Abrams Addison-Wesley Upper Saddle River, NJ Boston Indianapolis San Francisco New York Toronto Montreal London Munich Paris Madrid Capetown Sydney Tokyo Singapore Mexico City

Contents Figures xiii Tables xv Foreword xvii Preface xix Acknowledgments About the Authors xxv xxvii 1 Introduction 1 1.1 Qualities of a Well-Designed Framework 3 1.1.1 Well-Designed Frameworks Are Simple 3 1.1.2 Well-Designed Frameworks Are Expensive to Design 3 1.1.3 Well-Designed Frameworks Are Full of Trade-Offs 4 1.1. A Well-Designed Frameworks Borrow from the Past 5 1.1.5 Well-Designed Frameworks Are Designed to Evolve 5 1.1.6 Well-Designed Frameworks Are Integrated 5 1.1.7 Well-Designed Frameworks Are Consistent 6 2 Framework Design Fundamentals 7 2.1 Progressive Frameworks 9 2.2 Fundamental Principles of Framework Design 12 2.2.1 The Principle of Scenario-Driven Design 13 2.2.2 The Principle of Low Barrier to Entry 19 2.2.3 The Principle of Self-Documenting Object Models 23 2.2 A The Principle of Layered Architecture 29 2.3 Summary 31 VII

3 Naming Guidelines 33 3.1 Capitalization Conventions 34 3.1.1 Capitalization Rules for Identifiers 34 3.1.2 Capitalizing Acronyms 36 3.1.3 Capitalizing Compound Words and Common Terms 39 3.1.4 Case Sensitivity 41 3.2 General Naming Conventions 41 3.2.1 Word Choice 42 3.2.2 Using Abbreviations and Acronyms 43 3.2.3 Avoiding Language-Specific Names 44 3.2.4 Naming New Versions of Existing APIs 46 3.3 Names of Assemblies and DLLs 48 3.4 Names of Namespaces 49 3.4.I Namespaces and Type Name Conflicts 51 3.5 Names of Classes, Structs, and Interfaces 54 3.5.1 Names of Generic Type Parameters 56 3.5.2 Names of Common Types 57 3.5.3 Naming Enumerations 59 3.6 Names of Type Members 60 3.6.1 Names of Methods 60 3.6.2 Names of Properties 61 3.6.3 Names of Events 63 3.6.4 Naming Fields 64 3.7 Naming Parameters 64 3.8 Naming Resources 65 3.9 Summary 66 4 Type Design Guidelines 67 4.1 Types and Namespaces 69 4.1.1 Standard Subnamespace Names 73 4.2 Choosing Between Class and Struct 74 4.3 Choosing Between Class and Interface 77 4.4 Abstract Class Design 83 4.5 Static Class Design 85 4.6 Interface Design 86

4.7 Struct Design 89 4.8 Enum Design 91 4.8.1 Designing Flag Enums 97 4.8.2 Adding Values to Enums 100 4.9 Nested Types 101 4.10 Summary 104 5 Member Design 105 5.1 General Member Design Guidelines 105 5.1.1 Member Overloading 105 5.1.2 Implementing Interface Members Explicitly 111 5.1.3 Choosing Between Properties and Methods 115 5.2 Property Design 120 5.2.1 Indexed Property Design 122 5.2.2 Property Change Notification Events 124 5.3 Constructor Design 125 5.3.1 Type Constructor Guidelines 131 5.4 Event Design 132 5.4.1 Custom Event Handler Design 138 5.5 Field Design 139 5.6 Operator Overloads 141 5.6.1 Overloading Operator == 146 5.6.2 Conversion Operators 146 5.7 Parameter Design 148 5.7.1 Choosing Between Enum and Boolean Parameters 150 5.7.2 Validating Arguments 152 5.7.3 Parameter Passing 155 5.7.4 Members with Variable Number of Parameters 157 5.7.5 Pointer Parameters 161 5.8 Summary 162 6 Designing for Extensibility 163 6.1 Extensibility Mechanisms 163 6.1.1 Unsealed Classes 164 6.1.2 Protected Members 165 6.1.3 Events and Callbacks 166

6.1.4 Virtual Members 168 6.1.5 Abstractions (Abstract Types and Interfaces) 170 6.2 Base Classes 172 6.3 Sealing 174 6.4 Summary 177 7 Exceptions 179 7.1 Exception Throwing 183 7.2 Choosing the Right Type of Exception to Throw 189 7.2.1 Error Message Design 189 7.2.2 Exception Handling 191 7.2.3 Wrapping Exceptions 195 7.3 Using Standard Exception Types 197 7.3.1 Exception and SystemException 197 7.3.2 ApplicationException 197 7.3.3 InvalidOperationException 198 7.3.A ArgumentException, ArgumentNullException, and ArgumentOutOfRangeException 198 7.3.5 NullReferenceException, IndexOutOfRangeException, and AccessViolationException 199 7.3.6 StackOverflowException 200 7.3.7 OutOfMemoryException 200 7.3.8 ComException, SEHException, and other CLR Exceptions 201 7.3.9 ExecutionEngineException 201 7.4 Designing Custom Exceptions 202 7.5 Exceptions and Performance 203 7.5.1 Tester-Doer Pattern 203 7.5.2 Try-Parse Pattern 204 7.6 Summary 205 8 Usage Guidelines 207 8.1 Arrays 207 8.2 Attributes 209 8.3 Collections 211 8.3.1 Collection Parameters 213 8.3.2 Collection Properties and Return Values 214

8.3.3 Choosing Between Arrays and Collections 218 8.3.4 Implementing Custom Collections 219 8.4 ICloneable 221 8.5 IComparable<T> and IEquatable<T> 222 8.6 IDisposable 223 8.7 Object 224 8.7.1 Object.Equals 224 8.7.2 Object.GetHashCode 225 8.7.3 Object. ToString 227 8.8 Uri 228 8.8.1 System. Uri Implementation Guidelines 229 8.9 System.Xml Usage 230 8.10 Equality Operators 231 8.10.1 Equality Operators on Value Types 232 8.10.2 Equality Operators on Reference Types 232 9 Common Design Patterns 235 9.1 Aggregate Components 235 9.1.1 Component-Oriented Design 237 9.1.2 Factored Types 240 9.13 Aggregate Component Guidelines 240 9.2 The Async Pattern 243 9.2.1 Async Pattern Basic Implementation Example 247 9.3 Dispose Pattern 248 9.3.1 Basic Dispose Pattern 251 9.3.2 Finalizable Types 256 9.4 Factories 260 9.5 Optional Feature Pattern 264 9.6 Template Method 267 9.7 Timeouts 269 9.8 And in the End... 271 A C# Coding Style Conventions 273 A.I General Style Conventions 274

A. 1.1 Brace Usage 274 A.I.2 Space Usage 275 A. 1.3 Indent Usage 276 A. 2 Naming Conventions 277 A3 Comments 277 A.4 File Organization 278 B Using FxCop to Enforce the Design Guidelines 281 B.I WhatlsFxCop? 281 B.2 The Evolution of FxCop 282 B.3 How Does It Work? 283 B.4 FxCop Guideline Coverage 284 B.4.1 FxCop Rules for the Naming Guidelines 284 B.4.2 FxCop Rules for the Type Design Guidelines 293 B.4.3 FxCop Rules for Member Design 296 B.4.4 FxCop Rules for Designing for Extensibility 302 B.4.5 FxCop Rules for Exceptions 303 B.4.6 FxCop Rules for Usage Guidelines 305 B.4.7 FxCop Rules for Design Patterns 309 C Sample API Specification 311 Glossary 319 Suggested Reading List 323 Index 327