C# Design Patterns: A Tutorial

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

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. This text is a practical guide to writing C# programs using the most common patterns.

Author(s): James William Cooper
Edition: Book and CD-ROM
Publisher: Addison-Wesley Professional
Year: 2002

Language: English
Pages: 384

Table of Contents
Main
Copyright
Preface
Acknowledgments
Part I: Object-Oriented Programming in C#
Chapter 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
Chapter 2. Syntax of the C# Language
Data Types
Converting between Numbers and Strings
Declaring Multiple Variables
Numeric Constants
Character Constants
Variables
Multiple Equal 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
Chapter 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
The Windows Controls Program
Summary
Programs on the CD-ROM
Chapter 4. Using Classes and Objects in C#
What Do We Use Classes For?
A Simple Temperature Conversion Program
Building a Temperature Class
Putting the Decisions into the Temperature Class
Using Classes for Format and Value Conversion
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
Chapter 5. Inheritance
Constructors
Drawing and Graphics in C#
Using Inheritance
Namespaces
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
Chapter 6. UML Diagrams
Inheritance
Interfaces
Composition
Annotation
WithClass UML Diagrams
C# Project Files
Chapter 7. Arrays, Files, and Exceptions in C#
Arrays
Collection Objects
Exceptions
Multiple Exceptions
Throwing Exceptions
File Handling
Exceptions in File Handling
Testing for End of File
A csFile Class
Program on the CD-ROM
Part II: Creational Patterns
Chapter 8. The Simple Factory Pattern
How a Simple Factory Works
How a Simple Factory Works
The Two Derived Classes
Building the Simple Factory
Factory Patterns in Math Computation
Summary
Thought Questions
Programs on the CD-ROM
Chapter 9. The Factory Method
The Swimmer Class
The Events Classes
StraightSeeding
Our Seeding Program
Other Factories
When to Use a Factory Method
Thought Question
Program on the CD-ROM
Chapter 10. The Abstract Factory Pattern
A GardenMaker Factory
Adding More Classes
Consequences of Abstract Factory
Thought Question
Program on the CD-ROM
Chapter 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
Chapter 12. The Builder Pattern
An Investment Tracker
Using the Items Collection in the ListBox Control
Consequences of the Builder Pattern
Thought Questions
Program on the CD-ROM
Chapter 13. The Prototype Pattern
Cloning in C#
Using the Prototype
Cloning the Class
Using the Prototype Pattern
Prototype Managers
Consequences of the Prototype Pattern
Thought Question
Programs on the CD-ROM
Summary of Creational Patterns
Part III: Structural Patterns
Chapter 14. The Adapter Pattern
Moving Data between Lists
Making an Adapter
Using the DataGrid
Using a TreeView
The Class Adapter
Two-Way Adapters
Object versus Class Adapters in C#
Pluggable Adapters
Thought Question
Programs on the CD-ROM
Chapter 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
Chapter 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
Chapter 17. The Decorator Pattern
Decorating a CoolButton
Handling Events in a Decorator
Multiple Decorators
Nonvisual Decorators
Decorators, Adapters, and Composites
Consequences of the Decorator Pattern
Thought Questions
Programs on the CD-ROM
Chapter 18. The Façade Pattern
What Is a Database?
Getting Data Out of Databases
Kinds of Databases
ODBC
Database Structure
Using ADO.NET
Adding Rows to Database Tables Using ADO.NET
Building the Façade Classes
Making the ADO.NET Façade
Creating Classes for Each Table
Building the Price Table
Loading the Database Tables
The Final Application
What Constitutes the Façade?
Consequences of the Façade
Thought Question
Program on the CD-ROM
Chapter 19. The Flyweight Pattern
Discussion
Example Code
Handling the Mouse and Paint Events
Flyweight Uses in C#
Sharable Objects
Copy-on-Write Objects
Thought Question
Program on the CD-ROM
Chapter 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
Part IV: Behavioral Patterns
Chapter 21. Chain of Responsibility
Applicability
Sample Code
ListBoxes
Programming a Help System
A Chain or a Tree?
Kinds of Requests
Examples in C#
The Chain of Responsibility
Thought Question
Programs on the CD-ROM
Chapter 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
Chapter 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
Consequences of the Interpreter Pattern
Thought Question
Program on the CD-ROM
Chapter 24. The Iterator Pattern
Motivation
Sample Iterator Code
Filtered Iterators
Keeping Track of the Clubs
Consequences of the Iterator Pattern
Programs on the CD-ROM
Chapter 25. The Mediator Pattern
An Example System
Interactions between Controls
Sample Code
Consequences of the Mediator Pattern
Single Interface Mediators
Implementation Issues
Program on the CD-ROM
Chapter 26. The Memento Pattern
Motivation
Implementation
Sample Code
Command Objects in the User Interface
Handling Mouse and Paint Events
Consequences of the Memento
Thought Question
Program on the CD-ROM
Chapter 27. The Observer Pattern
Watching Colors Change
The Message to the Media
Consequences of the Observer Pattern
Program on the CD-ROM
Chapter 28. The State Pattern
Sample Code
Switching between States
How the Mediator Interacts with the StateManager
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
Chapter 29. The Strategy Pattern
Motivation
Sample Code
The Context
The Program Commands
The Line and Bar Graph Strategies
Drawing Plots in C#
Consequences of the Strategy Pattern
Program on the CD-ROM
Chapter 30. The Template Method Pattern
Motivation
Kinds of Methods in a Template Class
Sample Code
The Triangle Drawing Program
Templates and Callbacks
Summary and Consequences
Programs on the CD-ROM
Chapter 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