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.
This is a good time to mention that you can implement a provider design pattern similar to the one used for Membership and Profile, which we'll cover in Chapter 11, "Membership and Security," and Chapter 12, "Profiles, Themes, and Skins." |