Component-based Development with Visual C#
Published in 2002 by M&T Books, a division of John Wiley & Sons
978 pages - ISBN: 0-764-54914-6
Component-based Development (CBD) is the latest software trend that takes the object-oriented programming paradigm to new heights. This book is written for the medium to advanced developer, and covers the full spectrum of multi-tier software development from a component perspective. All the code samples are described using UML diagrams. All the C# code for the book can be downloaded here.
Table of Contents
Part 1 – General Topics
This first part is devoted to general topics that aren't programming-language specific. If you are less interested in theoretical issues, and more interested in getting results with C#, you can safely skip the entire section and go straight to Part 2, where the coding chapters start.
Chapter 1 – The Development Process
Chapter 1 describes the software development as an iterative process, comprised of Analysis, Design and Implementation phases that interact in a successive-approximations manner. In the new CBD paradigm, testing is viewed as an integral part of all phases, and no longer an after-the-fact activity. Find out how to use DDR and FFR metrics to determine when your components are ready to be released.
Chapter 2 – Component Structure
What do components look like, on the inside? What are the hallmarks of a well-designed component? Chapter 2 discusses the importance of simplicity and its relationship to quality. It introduces the 10-10-10 rule for components. Important design structures, such as aggregation, delegation, supercomponents and subcomponents, are also described.
Chapter 3 – Component Design
This chapter lists the key software design patterns in use in the component world. UML is introduced as a design tool and all the patterns are described with UML. The chapter also lists desirable features of components, such as low coupling with other components, low complexity, maintainability and others.
Chapter 4 – Component Classifications
What types of components exist, and how are they classified? Chapter 4 describes several ways to classify components. The subject of classification is important, because in the growing world of components, proper classification will make it easier to catalog and ultimately find components available in the marketplace. With the growth of the Internet as a searchable medium, and the availability of components that can be downloaded with a mouse click, the market for components is expected to grow exponentially, making classification an important topic.
Chapter 5 – Component Debugging
This chapter goes into details on how to debug all types of components, from stand-alone Windows applications to distributed systems. The focus is on Visual Studio's advanced debugging features.
Chapter 6 – Component Deployment
Your software is useless, unless you can get it to run on your customers' machines. Deployment is about taking a developed project, packaging the components and getting them to run on a target machine. This chapter shows how to create a customized Setup program using the Visual Studio wizards, and how to optimize the runtime performance of your components using NGEN, the Microsoft compiler that can be used to precompile IL code into native machine code.
Part 2 – Front-End Components
This is where the fun starts. The chapters in this section are dedicated to user interface components of Windows applications. For user interfaces based on HTML pages, see Part 3.Chapter 7 – Windows Form Components
This chapter takes you through the design and implementation of a sample application called ProcessViewer, a stand-alone Windows program that displays details about the Win32 processes running on a system. The program shows how to create Windows Explorer-type interfaces, with a treelist control on the left and a set of content pages on the right. The program shows how to implement a host of commonly-used features, such as managing content pages, handling command-line arguments, printing, using regular expressions and supporting cut-and-paste.Chapter 8 – Reusing the Web Browser Component
This chapter shows how to embed the Microsoft WebBrowser component into a Windows Form to create powerful user interfaces that can handle a wide variety of content types, such as Microsoft documents created with Word, Excel and PowerPoint, HTML pages, RTF documents, JPEG, PNG and GIF images and others. The second part of the chapter shows how to use COM interoperability code to customize the WebBrowser. A complete example shows how to change WebBrowser features using the IDocHostUIHandler and IDocHostShowUI interfaces. Find out how to achieve customizations like these:
removing the vertical scrollbar from HTML documents
disabling the autocomplete feature
customizing the context menu
preventing users from navigating to a hyperlinked document
disabling or changing the way accelerator keys work
See how to implement the WebBrowser customization interfaces using C#, and how to find information on other important COM interfaces that are useful in many different situations.Chapter 9 – Custom Controls
This chapter shows how to design and implement a custom control. It shows how to do your own custom drawing, using both GDI and GDI+ objects and methods. The chapter uses UML and sample code to show how to handle input focus, the mouse and the keyboard. A significant discussion is made regarding World Transforms, showing how to support advanced drawing techniques to achieve zooming, rotation, shearing and translation using GDI+ primitives and matrices. The sample custom control discussed in the chapter shows how to implement a variety of other features, such as adding a context menu, drawing translucent objects, searching the file system, supporting drag and drop, and using random numbers. The last part of the chapter is devoted to design-time properties, which are properties of custom types that can be supported using the Visual Studio.NET Properties window.Chapter 10 – User Controls
User controls act like a panel, allowing other controls to be embedded on them. In this chapter, see how to implement your own User Controls and implement a number of useful features such as:
- Managing rectangles
- Drawing rubberbands
- Checking mouse buttons and location
- Controlling the cursor
- Constraining the mouse cursor inside an area
- Drawing selection frames
- Drawing grab handles
- Resizing objects on the screen
- Drawing shapes
- System IconsChapter 11 – Database Front Ends
This chapter shows a number of ways to create user interfaces for Windows applications that display items in a database. This is the longest chapter in the book, with nearly 100 figures by itself. The following UI presentations are shown in full detail:
Database Report forms
See how to create professional-looking database front-ends using the new Crystal Reports components that are now tightly bound to Visual Studio.NET. Two different types of reports are shown in detail, illustrating such advanced topics as calculated fields, grouping, summary totals and grand totals.Chapter 12 – Tips for the Front-End
There are a number of topics that relate to all types of front-end components, so they were grouped together in a chapter by themselves. In this chapter, see how to accomplish the following:
Implementing Splash screens
Saving user preferences
Accessing the Windows registry
Dealing with text and binary files
Handling Most-Recently-Used file lists
Creating Windows Shell shortcuts, using COM interop
Implementing standard COM interfaces
Part 3 – Middle-Tier Components
This section deals primarily with ASP.NET and web-related components. The exception is chapter 16, part of which is devoted to Windows services.Chapter 13 – Web Forms
In this chapter I describe ASP.NET Web Forms and how they work. A number of UML diagrams show the interactions between IIS, the HTTP runtime, the operating system and your Web Forms. Find out what postbacks are and how to handle them. Explore the new event model of ASP.NET and see how to use the ASP.NET environment to manage user state in Web Applications of all sizes. A complete example is shown, with full details on how to use Trace statements and the Response object to facilitate testing.Chapter 14 – Web Controls
Learn how to create your own Web custom controls that work with different types and versions of browsers. See how to add custom properties and events to a Web Control. A considerable amount of space is given to the discussion of User Input Validation, using the following built-in validators:
The chapter wraps up with a complete example showing the use of in-place validators and ValidationSummary.Chapter 15 – User Controls
Web User Controls are similar to panels that can contain any number of standard or custom Web Controls. This chapter shows how to create a sample Web Application that employs User Controls to implement a Navigator and Content section for a Windows-Explorer-style interface. See how to add properties and events to your User Controls. The chapter also shows how to create Frame-based HTML pages using Visual Studio.NET. The last part of the chapter discusses how to convert a User Control into a Web Form, and also cover a number of testing and deployment issues.Chapter 16 – Services
This chapter discusses two types of services: Web Services and Windows services. The former are Web-accessible components that expose a service using the Internet. The latter are special types of programs that run with no user interfaces and act somewhat like extensions of the operating system. Regarding Web Services, this chapter describes how they work, what technologies they use, how to built them and test them. A discussion is also made on how to maintain user state and how to support various types of security arrangements with Web Service components.
The second part of the chapter deals with Windows services. Find out not only how to design and implement a Windows service component, but also how to control it with a Service Control Program and how to show service status using Service Tray icons. Particular emphasis is given to testing, which is notoriously difficult with Windows Services for two reasons:
services run under a special user account with privileges that may be different from those of the user currently logged into the system
services generally don't have a user interface, so they can't display message boxes, dialog boxes or any other type of item to the user sitting in front of the computer.Chapter 17 – Security
The chapter deals less with coding issues and more with Windows 2000 security topics. Most books written for developers tend to avoid detailed discussions of security, since the topic is often the responsibility of Systems or Network Administrators. This chapter walks you through many of the steps required to configure Web security, to avoid exposing your Web Applications and Web Services to hackers. See how to create and setup new User Accounts that grant only those privileges that are needed by your users. Learn how to authenticate users with different techniques, and find out which one is best for your situation.
Part 4 – Back-End Components
Chapter 18 – The ADO.NET Architecture
Find out what ADO.NET is all about, and how this radically new database component infrastructure works. UML diagrams are used to show how the key components interact with each other. Learn how to implement the following features
using disconnected recordsets
locating records in a recordset
database connection pooling
A complete example is also provided, showing how to insert, update and delete records from a database using a Web Service on the middle-tier or back-end. Space is also given to a discussion of database exception handling and error reconciliation.Chapter 19 – Database Services
This chapter is a marriage between ADO.NET and Web Services. It shows a complete example on how to expose access to a database using an ASP.NET Web Service. Considerable space is devoted to testing, how to deal with errors and how to use transactions for database integrity.Chapter 20 – Multithreaded Components
This chapter shows how to use threads to achieve high performance programs. See how to synchronize threads using semaphores, mutexes and critical sections. See how to use threads to achieve non-blocking calls, and find out how the .NET Framework's Asynchronous Programming Model works. The chapter shows how to use threads in your own programs, and also how to use the built-in .NET thread pool. The chapter concludes with the design and implementation of a complete multi-threaded component called StressTester, than can be used to test a multi-threaded component with a configurable number of concurrent requests.Chapter 21 – Gateway Services
Gateway Services are those that typically run on the back-end and connect to a remote service over a Wide-Area-Network of a dedicated leased line. Gateway Services are in widespread use today, handling everything from credit card processing to airline ticketing to customer credit reporting. The key features of Gateways Services are performance and scalability. See how to use the .NET Framework Remoting infrastructure to build scalable, high performance, multi-threaded Gateways using TCP sockets.