|
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Working with "ASP classes" is really cool and I am sure, if you read this article, you will also start to write an application in ASP using classes. (Unless you go for ASP .NET) I am very grateful to Dave Cline, who taught me how to work with Classes in ASP. In order to know more about this article, I assume the reader has knowledge in Object Oriented Programming Structure (OOPS) How can we declare classes in ASP?Classes in ASP can be declared as follows
Now. we will go through each line of the above declaration. Line 1 declares a class called YourClassName Line 2 to Line 4 deals with declaring properties on this class. You can declare either a property to be Private or Public. As VBScript only deals with Variants, we cannot specify the dataType of each property. Their should be a way to communicate with these private and public properties. So, we need to have methods which talks with these properties. To know more about, Object Oriented Programming in C++, click here Note: Unless declared Private, all properties and methods are public.Now, we will see an sample ASP page and a samle class file, which deals with Following is the
In the above class file, we have three private properties and two public methods which communicate with the properties. In the following ASP page, we will see, how to invoke the above class.
In the above ASP page, we are including the Classes.clas file as the first statement. Then in the procedure called Initialize, we create an instance of class, test. Then, we are passing assigning values to the three properties using the interface (method) assign_values. After that, using the interface GetValues, we are retrieving the values of those three properties. The above is just an example that depicts the usage of classes in ASP. Although, the example just assigns some values to the properties and retrieves those values with the help of another method. We can do a lots of things with classes. The following example Now, we are going to see a real time example for the use of classes. We are going to create a class called Student, which can hold details of students. We have four properties and two methods. First lets look into the Class definition
Now, we will see the ASP page, which uses this class.
SummaryThis is just a simple example. You can also use the dictionary object as one of the property in the Class Definition and you can and fill up the dictionary objects and you can use them, while displaying a recordset. As we are using OOP concept, all the advantages of OOP applies in this example too. Happy Programming. External Linkshttp://www.gnacademy.org/text/cc/Tutorial/tutorial.htmlhttp://java.sun.com/docs/books/tutorial/java/concepts/ Send your comments to das@aspalliance.com Back to Article list |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||