Analyzing Design Requirements
The first step in designing any class is to identify your needs in human terms before writing code. In our case, we want to make it easy to get, update, and delete data from a table called Customers in SQL Server. None of the columns in our table allows null values.
CustomerID (primary key/identity) | int |
---|---|
LastName | nvarchar |
FirstName | nvarchar |
Address | nvarchar |
City | nvarchar |
State | nvarchar |
Zip | nvarchar |
Phone | nvarchar |
SignUpDate | datetime |
Why are we using nvarchar instead of varchar? The difference is that nvarchar uses Unicode, the generally accepted standard of character encoding that includes a much larger character set. Using Unicode in your Web application means there's less chance of getting weird characters generated by users in other countries. The tradeoff is that it takes up twice as much disk space, but in an age of giant inexpensive hard drives, this should hardly be a concern.We know that the Customers table has nine columns that we can manipulate. We also know that we want to create, update, and delete records in this table. The most obvious need we'll have is to get data from the table. After we have the basics of our class nailed down, we'll revise the class to cache data and explore ways to get a number of records at one time.