Summary
Our custom data class represents a block of code that manipulates data in our database. If you look back to the code samples at the beginning of the chapter, you can see that a few simple properties and methods replace the blocks of data access code that we would otherwise need to write over and over again in our application, in any place that we would need to change data in our database.
This encapsulation of common functionality gets to the core of writing object-oriented code. We achieve code reuse, and we manipulate an object with names we understand. The purpose of our Update() method is not immediately apparent, based on the appearance of the code. Compare that to the first code sample, where we create a Customer object, assign new values to its properties, and then call its Update() method. This code is much easier to deal with, and its purpose is almost immediately obvious. Again, we can view the code from a "user" view and a "programmer" view, the former concentrating on how it's used, and the latter worrying about the underlying implementation.
Data access is just one problem you can address with your own classes. If you start to think in abstract terms of a tool that solves a problem, you can apply similar concepts to virtually anything. For example, if you needed a tool that checked loan balances for a bank customer service representative, you might create a balance checking class that takes some parameters or properties that represent the customer and some method or property that indicates the balance due. You might also include methods that verify the customer's information or that check to see whether they've paid on time or whether the customer service representative has permission to look up the balance. This tool might be used by a Web site or a Windows application, or it might be used by another system, such as a system that takes new loan applications and makes decisions based on the customer's payment history from your balance checking tool.
Microsoft has solved hundreds or thousands of problems like this. Take our friend the TextBox control. Here Microsoft has created a tool, a class just like one you might build, that renders HTML to the browser, stores data in the control's viewstate, and generates style information if it's needed, among other things. It's a lot easier than having to do all that work over and over again in the context of every page!