C# Design Patterns : A Tutorial / With CD / Edition 1

Paperback (Print)
Buy Used
Buy Used from BN.com
$41.17
(Save 41%)
Item is in good condition but packaging may have signs of shelf wear/aging or torn packaging.
Condition: Used – Good details
Used and New from Other Sellers
Used and New from Other Sellers
from $1.99
Usually ships in 1-2 business days
(Save 97%)
Other sellers (Paperback)
  • All (25) from $1.99   
  • New (5) from $58.74   
  • Used (20) from $1.99   

Overview

Design patterns are elegant, adaptable, and reusable solutions to everyday software development problems. Programmers use design patterns to organize objects in programs, making them easier to write and modify. C# Design Patterns: A Tutorial is a practical guide to writing C# programs using the most common patterns.

This tutorial begins with clear and concise introductions to C#, object-oriented programming and inheritance, and UML diagrams. Each chapter that follows describes one of twenty-three design patterns, recommends when to use it, and explains the impact that it will have on the larger design. The use of every pattern is demonstrated with simple example programs. These programs are illustrated with screen shots and UML diagrams displaying how the classes interact. Each of these programs is available on the companion CD-ROM and can be run, examined, edited, and applied.

Design patterns will have an immediate impact on your work as you learn the following:

  • Applying design patterns effectively in your day-to-day programming
  • Using patterns to create sophisticated, robust C# programs
  • The interaction of classes as demonstrated by UML diagrams
  • Advancing your programming skills using design patterns

Design patterns will not only enhance your productivity, but once you see how quickly and easily object-oriented code can be recycled, they will become an everyday part of your C# programming.

0201844532B05232002

Read More Show Less

Product Details

  • ISBN-13: 9780201844535
  • Publisher: Addison-Wesley
  • Publication date: 2/28/2003
  • Edition description: New Edition
  • Edition number: 1
  • Pages: 392
  • Product dimensions: 7.30 (w) x 9.00 (h) x 1.00 (d)

Meet the Author

James W. Cooper is a research staff member in the Advanced Information Retrieval and Analysis Department at the IBM Thomas J. Watson Research Center. He is also a columnist for Java Pro magazine and a reviewer for Visual Basic Programmer's Journal. He has published 14 books, which include Principles of Object-Oriented Programming Using Java 1.1 (Ventana) and The Visual Basic Programmer's Guide to Java (Ventana).

0201844532AB05132002

Read More Show Less

Read an Excerpt

This is a practical book that tells you how to write C# programs using some of the most common design patterns. It also serves as a quick introduction to programming in the new C# language. The pattern discussions are structured as a series of short chapters, each describing a design pattern and giving one or more complete working, visual example programs that use that pattern. Each chapter also includes UML diagrams illustrating how the classes interact.

This book is not a "companion" book to the well-known Design Patterns text by the "Gang of Four." Instead, it is a tutorial for people who want to learn what design patterns are about and how to use them in their work. You do not have to have read Design Patterns to read this book, but when you are done here, you may well want to read or reread it to gain additional insights.

In this book, you will learn that design patterns are frequently used ways of organizing objects in your programs to make them easier to write and modify. You'll also see that by familiarizing yourself with them, you've gained some valuable vocabulary for discussing how your programs are constructed.

People come to appreciate design patterns in different ways—from the highly theoretical to the intensely practical—and when they finally see the great power of these patterns, an "Aha!" moment occurs. Usually this is the moment when you discover how that pattern can help you in your work.

In this book, we try to help you form that conceptual idea, or gestalt, by describing the pattern in as many ways as possible. The book is organized into six main sections: an introductory description, an introduction to C#, and descriptions of patterns that are grouped as creational, structural, and behavioral.

For each pattern, we start with a brief verbal description and then build simple example programs. Each of these examples is a visual program that you can run and examine to make the pattern as concrete a concept as possible. All of the example programs and their variations are on the companion CD-ROM, where you run them, change them, and see how the variations you create work.

Since each of the examples consists of a number of C# files for each of the classes we use in that example, we provide a C# project file for each example and place each example in a separate subdirectory to prevent any confusion. This book assumes you have and will be using a copy of Visual Studio.NET, which comes in several versions. We used the Professional Edition in developing the code samples.

If you leaf through the book, you'll see screenshots of the programs we developed to illustrate the design patterns, providing yet another way to reinforce your learning of these patterns. In addition, you'll see UML diagrams of these programs, illustrating the interactions between classes in yet another way. UML diagrams are just simple box-and-arrow illustrations of classes and their inheritance structure, where arrows point to parent classes, and dotted arrows point to interfaces. And if you're not yet familiar with UML, we provide a simple introduction in the second chapter. All of the diagrams were produced using WithClass 2000, and a demonstration version of that program is included on the CD-ROM.

When you finish this book, you'll be comfortable with the basics of design patterns and will be able to start using them in your day-to-day C# programming work.

James W. Cooper Nantucket, MA Wilton, CT Kona, HI

Read More Show Less

Table of Contents

Preface.

Acknowledgments.

I. OBJECT-ORIENTED PROGRAMMING IN C#.

1. What Are Design Patterns?

Defining Design Patterns.

The Learning Process.

Studying Design Patterns.

Notes on Object-Oriented Approaches.

C# Design Patterns.

How This Book Is Organized.

2. Syntax of the C# Language.

Data Types.

Converting between Numbers and Strings.

Declaring Multiple Variables.

Numeric Constants.

Character Constants.

Variables.

Declaring Variables as You Use Them.

Multiple Equals Signs for Initialization.

A Simple C# Program.

Arithmetic Operators.

Increment and Decrement Operators.

Combining Arithmetic and Assignment Statements.

Making Decisions in C#.

Comparison Operators.

Combining Conditions.

The Most Common Mistake.

The Switch Statement.

C# Comments.

The Ornery Ternary Operator.

Looping Statements in C#.

The While Loop.

The Do-While Statement.

The For Loop.

Declaring Variables as Needed in For Loops.

Commas in For Loop Statements.

How C# Differs from C.

How C# Differs from Java.

Summary.

3. Writing Windows C# Programs.

Objects in C#.

Managed Languages and Garbage Collection.

Classes and Namespaces in C#.

Building a C# Application.

The Simplest Window Program in C#.

Windows Controls.

Labels.

TextBox.

CheckBox.

Buttons.

Radio Buttons.

ListBoxes and ComboBoxes.

The Items Collection.

Menus.

ToolTips.

The Windows Controls Program.

Summary.

Programs on the CD-ROM.

4. Using Classes and Objects in C#.

What Do We Use Classes For?

A Simple Temperature Conversion Program.

Building a Temperature Class.

Converting to Kelvin.

Putting the Decisions into the Temperature Class.

Using Classes for Format and Value Conversion.

Handling Unreasonable Values.

A String Tokenizer Class.

Classes as Objects.

Class Containment.

Initialization.

Classes and Properties.

Programming Style in C#.

Delegates.

Indexers.

Operator Overloading.

Summary.

Programs on the CD-ROM.

5. Inheritance.

Constructors.

Drawing and Graphics in C#.

Using Inheritance.

Namespaces.

Creating a Square from a Rectangle.

Public, Private, and Protected.

Overloading.

Virtual and Override Keywords.

Overriding Methods in Derived Classes.

Replacing Methods Using New.

Overriding Windows Controls.

Interfaces.

Abstract Classes.

Comparing Interfaces and Abstract Classes.

Summary.

Programs on the CD-ROM.

6. UML Diagrams.

Inheritance.

Interfaces.

Composition.

Annotation.

WithClass UML Diagrams.

C# Project Files.

7. Arrays, Files, and Exceptions in C#.

Arrays.

Collection Objects.

ArrayLists.

Hashtables.

SortedLists.

Exceptions.

Multiple Exceptions.

Throwing Exceptions.

File Handling.

The File Object.

Reading a Text File.

Writing a Text File.

Exceptions in File Handling.

Testing for End of File.

A csFile Class.

Program on the CD-ROM.

II. CREATIONAL PATTERNS.

8. The Simple Factory Pattern.

How a Simple Factory Works.

Sample Code.

The Two Derived Classes.

Building the Simple Factory.

Using the Factory.

Factory Patterns in Math Computation.

Summary.

Thought Questions.

Programs on the CD-ROM.

9. The Factory Method.

The Swimmer Class.

The Events Classes.

StraightSeeding.

CircleSeeding.

Our Seeding Program.

Other Factories.

When to Use a Factory Method.

Thought Question.

Program on the CD-ROM.

10. The Abstract Factory Pattern.

A GardenMaker Factory.

The PictureBox.

Handling the RadioButton and Button Events.

Adding More Classes.

Consequences of Abstract Factory.

Thought Question.

Program on the CD-ROM.

11. The Singleton Pattern.

Creating Singleton Using a Static Method.

Exceptions and Instances.

Throwing the Exception.

Creating an Instance of the Class.

Providing a Global Point of Access to a Singleton.

Other Consequences of the Singleton Pattern.

Programs on the CD-ROM.

12. The Builder Pattern.

An Investment Tracker.

The Stock Factory.

The CheckChoice Class.

The ListboxChoice Class.

Using the Items Collection in the ListBox Control.

Plotting the Data.

The Final Choice.

Consequences of the Builder Pattern.

Thought Questions.

Program on the CD-ROM.

13. The Prototype Pattern.

Cloning in C#.

Using the Prototype.

Cloning the Class.

Using the Prototype Pattern.

Dissimilar Classes with the Same Interface.

Prototype Managers.

Consequences of the Prototype Pattern.

Thought Question.

Programs on the CD-ROM.

Summary of Creational Patterns.

III. STRUCTURAL PATTERNS.

14. The Adapter Pattern.

Moving Data between Lists.

Making an Adapter.

Using the DataGrid.

Detecting Row Selection.

Using a TreeView.

The Class Adapter.

Two-Way Adapters.

Object versus Class Adapters in C#.

Pluggable Adapters.

Thought Question.

Programs on the CD-ROM.

15. The Bridge Pattern.

The Bridger Interface.

The VisList Classes.

The Class Diagram.

Extending the Bridge.

Windows Forms as Bridges.

Consequences of the Bridge Pattern.

Thought Question.

Programs on the CD-ROM.

16 The Composite Pattern.

An Implementation of a Composite.

Computing Salaries.

The Employee Classes.

The Boss Class.

Building the Employee Tree.

Self-Promotion.

Doubly Linked Lists.

Consequences of the Composite Pattern.

A Simple Composite.

Composites in .NET.

Other Implementation Issues.

Thought Questions.

Programs on the CD-ROM.

17. The Decorator Pattern.

Decorating a CoolButton.

Handling Events in a Decorator.

Layout Considerations.

Control Size and Position.

Multiple Decorators.

Nonvisual Decorators.

Decorators, Adapters, and Composites.

Consequences of the Decorator Pattern.

Thought Questions.

Programs on the CD-ROM.

18. The Facade Pattern.

What Is a Database?

Getting Data Out of Databases.

Kinds of Databases.

ODBC.

Database Structure.

Using ADO.NET.

Connecting to a Database.

Reading Data from a Database Table.

Executing a Query.

Deleting the Contents of a Table.

Adding Rows to Database Tables Using ADO.NET.

Building the Facade Classes.

Building the Price Query.

Making the ADO.NET Facade.

The DBTable Class.

Creating Classes for Each Table.

Building the Price Table.

Loading the Database Tables.

The Final Application.

What Constitutes the Facade?

Consequences of the Facade.

Thought Question.

Program on the CD-ROM.

19. The Flyweight Pattern.

Discussion.

Example Code.

The Class Diagram.

Selecting a Folder.

Handling the Mouse and Paint Events.

Flyweight Uses in C#.

Sharable Objects.

Copy-on-Write Objects.

Thought Question.

Program on the CD-ROM.

20. The Proxy Pattern.

Sample Code.

Proxies in C#.

Copy-on-Write.

Comparison with Related Patterns.

Thought Question.

Program on the CD-ROM.

Summary of Structural Patterns.

IV. BEHAVIORAL PATTERNS.

21. Chain of Responsibility.

Applicability.

Sample Code.

ListBoxes.

Programming a Help System.

Receiving the Help Command.

A Chain or a Tree?

Kinds of Requests.

Examples in C#.

The Chain of Responsibility.

Thought Question.

Programs on the CD-ROM.

22. The Command Pattern.

Motivation.

Command Objects.

Building Command Objects.

Consequences of the Command Pattern.

The CommandHolder Interface.

Providing Undo.

Thought Questions.

Programs on the CD-ROM.

23. The Interpreter Pattern.

Motivation.

Applicability.

A Simple Report Example.

Interpreting the Language.

Objects Used in Parsing.

Reducing the Parsed Stack.

Implementing the Interpreter Pattern.

The Syntax Tree.

Consequences of the Interpreter Pattern.

Thought Question.

Program on the CD-ROM.

24. The Iterator Pattern.

Motivation.

Sample Iterator Code.

Fetching an Iterator.

Filtered Iterators.

The Filtered Iterator.

Keeping Track of the Clubs.

Consequences of the Iterator Pattern.

Programs on the CD-ROM.

25. The Mediator Pattern.

An Example System.

Interactions between Controls.

Sample Code.

Initialization of the System.

Mediators and Command Objects.

Consequences of the Mediator Pattern.

Single Interface Mediators.

Implementation Issues.

Program on the CD-ROM.

26. The Memento Pattern.

Motivation.

Implementation.

Sample Code.

A Cautionary Note.

Command Objects in the User Interface.

Handling Mouse and Paint Events.

Consequences of the Memento.

Thought Question.

Program on the CD-ROM.

27. The Observer Pattern.

Watching Colors Change.

The Message to the Media.

Consequences of the Observer Pattern.

Program on the CD-ROM.

28. The State Pattern.

Sample Code.

Switching between States.

How the Mediator Interacts with the StateManager.

The ComdToolBarButton.

Handling the Fill State.

Handling the Undo List.

The VisRectangle and VisCircle Classes.

Mediators and the God Class.

Consequences of the State Pattern.

State Transitions.

Thought Questions.

Program on the CD-ROM.

29 The Strategy Pattern.

Motivation.

Sample Code.

The Context.

The Program Commands.

The Line and Bar Graph Strategies.

Drawing Plots in C#.

Making Bar Plots.

Making Line Plots.

Consequences of the Strategy Pattern.

Program on the CD-ROM.

30. The Template Method Pattern.

Motivation.

Kinds of Methods in a Template Class.

Sample Code.

Drawing a Standard Triangle.

Drawing an Isosceles Triangle.

The Triangle Drawing Program.

Templates and Callbacks.

Summary and Consequences.

Programs on the CD-ROM.

31. The Visitor Pattern.

Motivation.

When to Use the Visitor Pattern.

Sample Code.

Visiting the Classes.

Visiting Several Classes.

Bosses Are Employees, Too.

Catch-All Operations with Visitors.

Double Dispatching.

Why Are We Doing This?

Traversing a Series of Classes.

Consequences of the Visitor Pattern.

Thought Question.

Program on the CD-ROM.

Bibliography.

Index. 0201844532T08292002

Read More Show Less

Preface

This is a practical book that tells you how to write C# programs using some of the most common design patterns. It also serves as a quick introduction to programming in the new C# language. The pattern discussions are structured as a series of short chapters, each describing a design pattern and giving one or more complete working, visual example programs that use that pattern. Each chapter also includes UML diagrams illustrating how the classes interact.

This book is not a "companion" book to the well-known Design Patterns text by the "Gang of Four." Instead, it is a tutorial for people who want to learn what design patterns are about and how to use them in their work. You do not have to have read Design Patterns to read this book, but when you are done here, you may well want to read or reread it to gain additional insights.

In this book, you will learn that design patterns are frequently used ways of organizing objects in your programs to make them easier to write and modify. You'll also see that by familiarizing yourself with them, you've gained some valuable vocabulary for discussing how your programs are constructed.

People come to appreciate design patterns in different ways--from the highly theoretical to the intensely practical--and when they finally see the great power of these patterns, an "Aha!" moment occurs. Usually this is the moment when you discover how that pattern can help you in your work.

In this book, we try to help you form that conceptual idea, or gestalt, by describing the pattern in as many ways as possible. The book is organized into six main sections: an introductory description, an introduction to C#, and descriptions of patterns that are grouped as creational, structural, and behavioral.

For each pattern, we start with a brief verbal description and then build simple example programs. Each of these examples is a visual program that you can run and examine to make the pattern as concrete a concept as possible. All of the example programs and their variations are on the companion CD-ROM, where you run them, change them, and see how the variations you create work.

Since each of the examples consists of a number of C# files for each of the classes we use in that example, we provide a C# project file for each example and place each example in a separate subdirectory to prevent any confusion. This book assumes you have and will be using a copy of Visual Studio.NET, which comes in several versions. We used the Professional Edition in developing the code samples.

If you leaf through the book, you'll see screenshots of the programs we developed to illustrate the design patterns, providing yet another way to reinforce your learning of these patterns. In addition, you'll see UML diagrams of these programs, illustrating the interactions between classes in yet another way. UML diagrams are just simple box-and-arrow illustrations of classes and their inheritance structure, where arrows point to parent classes, and dotted arrows point to interfaces. And if you're not yet familiar with UML, we provide a simple introduction in the second chapter. All of the diagrams were produced using WithClass 2000, and a demonstration version of that program is included on the CD-ROM.

When you finish this book, you'll be comfortable with the basics of design patterns and will be able to start using them in your day-to-day C# programming work.

James W. Cooper
Nantucket, MA
Wilton, CT
Kona, HI

0201844532P08292002

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing all of 2 Customer Reviews
  • Anonymous

    Posted December 23, 2002

    For Intermediate C# Programmers

    C# Design Patterns demonstrates 23 different design patterns which are very useful in object-oriented programming. As the name of the title implies, this particular books focuses on showing these design patterns in the C# language, much like the author, James Cooper, has previously done for other languages such as Java and Visual Basic. If I had to rate the book overall, I would give it an "average" rating, as the book just doesn't seem to stand out among all the other titles available. The book seems to fit best with a specific audience. People who would benefit the most from this book are intermediate-level C# programmers, who know very little about object oriented design patters. If you are a beginner with C#, this book is not for you. The Basics of C# are covered very quickly in the first 7 chapters, but does not go into detail enough to help novice programmers. In fact, I cannot understand why those chapters are included at all. The materials in those chapters breeze over the C# language too fast for C# beginners, but at the same time, it is far too basic for those who have experience with C#. Beginners would be better suited picking up a introduction to C# book and working with the language for a little while before reading C# Design Patterns. Intermediate C# programmers with little knowledge of object-oriented design patterns will develop a new skill set from reading the book. The everyday usefulness of these design patterns makes a book on the subject a very worthwhile read. If the reader is already familiar with C# than this book is a good choice from them. The code samples presented in the book are well constructed and the accompanying CD provides has provided benefit whenever I wanted to see a full code listing. For certain code listings in the book, I would have liked to see a few more comments. Sometimes, it takes a little while to understand exactly what the author is doing with the code. The screenshots and figures do a very nice job representing the concepts visually. One of the best attributes in this book is the thought questions at the end of the chapter. They really get the reader to think and make sure they understand the concepts before continuing. Having a through understanding of each pattern is crucial as later patterns either build or use patterns which have already been learned. People who have read James Cooper's previous works such as Java Design Patterns or Visual Basic Design Patterns or Design Patterns by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides really do not have a need for this book. This book covers all of the same material as those other works. I have noticed several typos and minor mistakes throughout the book, which is getting far too common in technology books in general. With that aside, I would recommend this book to anyone who knows a good bit of C# and would like to learn about Design Patterns used in Object Oriented programming. I would also recommend that these people skip the first 7 chapters or quickly skim over them. As for anyone else, I would suggest passing on this title, and getting a book that caters to design principles in a language they are more familiar with.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted November 29, 2011

    No text was provided for this review.

Sort by: Showing all of 2 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)