In Hour 2 we discussed the ideas behind object-oriented programming. To refresh your memory, object-oriented programming is a programming paradigm in which the object is a key construct of the programming language. Objects contain methods, properties, and events. Properties define the state of the object, and methods perform some action. Events commonly represent state changes or indicate that some action has transpired.
Classes are the abstractions from which objects are created. To understand the relationship between a class and an object, think of a calculator. The calculator may have properties like current battery power, current value on the screen, last operation entered, and others. It might have methods like add, subtract, and so on. Its events might include clearing the last computation and turning off. If you were to sit down and list all of the properties, methods, and events that a calculator has, this list would be equivalent to a class. This list is an abstract idea of what a calculator is and what it does. It clearly is not a concrete representation of a calculator; you cannot use the list to compute the product of 19.34 and 78. An object, on the other hand, is a concrete representation of the class. The actual calculator that supports the properties, methods, and events outlined by the class is an object and is said to be an instance of the class it represents.
The Role of Objects in an ASP.NET Web ApplicationRecall from our earlier discussions that the .NET Framework contains a plethora of classes that allow for a variety of functionality. For example, each and every Web control that can be used in an ASP.NET page is represented by a class in the .NET Framework. There are also classes in the .NET Framework that allow for an email to be sent from a web page, for data to be retrieved from a database, for an image to be created, and so on. The source code portion of your ASP.NET web page can utilize the variety of functionality present in the .NET Framework. To use a class in the .NET Framework, we first must create an object from the particular class whose functionality we are interested in. Once we have an object, we may need to set some of the object's properties and call some of the object's methods. Additionally, we may want to create event handlers for some of the object's events. As we will see starting with Hour 13, "An Introduction to Databases," ASP.NET's DataSource Web controls make it possible to retrieve and work with databases without having to write a lick of code. However, sometimes you still may need to programmatically access database data. While we won't be examining how to programmatically access databases in this book, understand that there are a number of database-related classes in the .NET Framework, such as SqlConnection, SqlCommand, and SqlDataReader. The Four Common Tasks Performed with ObjectsWhen using objects, we'll perform four tasks again and again:
In the remainder of this hour, we will look at the Visual Basic syntax required to accomplish these four tasks. |