Beginning C# Object-Oriented Programming - Clark_ Dan.pdf

(24648 KB) Pobierz
805978206.008.png 805978206.009.png 805978206.010.png 805978206.011.png
 
For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
805978206.001.png 805978206.002.png
CONTENTS
Contents at a Glance
About the Author ........................................................................................................................ xii
About the Technical Reviewer ................................................................................................... xiii
Acknowledgments ..................................................................................................................... xiv
Introduction................................................................................................................................ xv
Chapter 1: Overview of Object-Oriented Programming ................................................................ 1
Chapter 2: Designing OOP Solutions: Identifying the Class Structure........................................... 7
Chapter 3: Designing OOP Solutions: Modeling the Object Interaction ...................................... 29
Chapter 4: Designing OOP Solutions: A Case Study ................................................................... 55
Chapter 5: Introducing the .NET Framework and Visual Studio.................................................. 77
Chapter 6: Creating Classes ..................................................................................................... 101
Chapter 7: Creating Class Hierarchies ...................................................................................... 115
Chapter 8: Implementing Object Collaboration......................................................................... 137
Chapter 9: Working with Collections ........................................................................................ 163
Chapter 10: Implementing the Data Access Layer.................................................................... 181
Chapter 11: Developing Windows Applications ........................................................................ 215
Chapter 12: Developing Web Applications ................................................................................ 243
Chapter 13: Developing and Consuming WCF Services ............................................................ 265
Chapter 14: Developing the OSO Application ............................................................................ 287
Chapter 15: Wrapping Up.......................................................................................................... 313
Appendix A: Fundamental Programming Concepts .................................................................. 317
Appendix B: Exception Handling in C#...................................................................................... 333
Appendix C: Installing the Required Software .......................................................................... 337
Index......................................................................................................................................... 343
iii
805978206.003.png 805978206.004.png 805978206.005.png 805978206.006.png
CONTENTS
Introduction
It has been my experience as a .Net trainer and lead programmer that most people do not have trouble
picking up the syntax of the language. What perplexes and frustrates many people are the higher-level
concepts of object-oriented programming methodology and design. To compound the problem, most
introductory programming books and training classes skim over these concepts or, worse, don’t cover
them at all. It is my hope that this book fills this void. My goal in writing this book is twofold. First, to
provide you with the information you need to understand the fundamentals of programming in C#.
Second and more importantly, to present you with the information required to master the higher-level
concepts of object-oriented programming methodology and design.
This book provides the knowledge you need to architect an object-oriented programming solution
aimed at solving a business problem. As you work your way through the book, you will learn first how to
analyze the business requirements of an application. Next, you will model the objects and relationships
involved in the solution design. Finally, you will implement the solution using C#. Along the way, you
will learn about the fundamentals of software design, the Unified Modeling Language (UML), object-
oriented programming, C#, and the .NET Framework.
Because this is an introductory book, it’s meant to be a starting point for your study of the topics it
presents. As such, this book is not designed to make you an expert in object-oriented programming and
UML; nor is it an exhaustive discussion of C# and the .NET Framework; nor is it an in-depth study of
Visual Studio. It takes considerable time and effort to become proficient in any one of these areas. It is
my hope that by reading this book, your first experiences in object-oriented programming will be
enjoyable and comprehensible—and that these experiences will instill a desire for further study.
Target Audience
The target audience for this book is the beginning C# programmer who wants to gain a foundation in
object-oriented programming along with the C# language basics. Programmers transitioning from a
procedural-oriented programming model to an object-oriented model will also benefit from this book.
In addition, there are many Visual Basic (VB) programmers who want to transition to C#. Before
transitioning to C#, it is imperative that you understand the fundamentals of object-oriented
programming.
Because the experience level of a “beginner” can vary immensely, I have included a primer in
Appendix A that discusses some basic programming concepts and how they are implemented in C#. I
would suggest you review these concepts if you are new to programming.
xv
805978206.007.png
INTRODUCTION
Organization of the Book
This book is organized into three parts:
Part 1 delves into object-oriented programming methodology and design—concepts that transcend
a particular programming language. The concepts presented are important to the success of an object-
oriented programming solution regardless of the implementation language chosen. At the conclusion of
this part, a case study walks you through the steps of modeling a real-world application.
Part 2 looks at how object-oriented programming is implemented in C#. You will look at creating
class structures, creating hierarchies, and implementing interfaces. This part also introduces object
interaction and collaboration. You will see how the object-oriented programming topics discussed in
Part 1 are transformed into C# coding constructs.
Part 3 covers creating .NET applications. You will learn how to develop a data access layer using the
classes that make up the ADO.NET set of namespaces. You will create a Windows-based user interface, a
web-based user interface, and a service-based programmatic interface. At the end of Part 3, you will
revisit the case study developed in Part 1 and transform the design into a fully functional C# application.
This includes creating a graphical user interface, implementing the business logic, and integrating with a
relational database to store data.
Activities and Software Requirements
One of the most important aspects of learning is doing. You can’t learn to ride a bike without jumping on
a bike, and you can’t learn to program without cranking out code. Any successful training program
needs to include both a theory component and a hands-on component.
I have included both components throughout this book. It is my hope that you will take seriously
the Activities I have added to each chapter and work through them thoroughly—even repeatedly.
Contrary to some students’ perception that these activities are “exercises in typing,” this is where you get
a chance to make the theory concrete and where true simulation of the concepts occurs. I also
encourage you to play as you work through an Activity. Don’t be afraid to alter some of the code just to
see what happens. Some of the best learning experiences occur when students “color outside the lines.”
The UML modeling activities in Part 1 are for someone using UMLet. I chose this program because
it’s a good diagramming tool to learn on. It lets you create UML diagrams without adding a lot of
advanced features associated with the high-end CASE tools. UMLet is a free open source tool and can be
downloaded from www.umlet.com . You can also use another tool such as Visio to complete the activities.
However, you don’t even need a tool to complete these activities; paper and pencil will work just fine.
The activities in Part 2 require Visual Studio 2010 Express with C# installed. I encourage you to
install the help files and make ample use of them while completing the activities. The activities in Part 3
require Microsoft SQL Server 2008 with the Pubs and Northwind databases installed. Appendix C
includes instructions on downloading and installing the sample databases. You can find free Express
editions of both Visual Studio 2010 and SQL Server 2008 at www.msdn.microsoft.com .
xvi
Zgłoś jeśli naruszono regulamin