Discussion and comparison of ASP object-oriented programming Blog selected from RAINMAN_NET
Keywords ASP object-oriented programming discussion and comparison
Source
ASP is a dynamic web programming technology launched by Microsoft in the early days, but it combines ADO's convenient and fast access to databases, combined with other technologies such as XML, COM/ActiveX to realize the multi-layer structure of the server, which has strong vitality today and still has certain developments. Although it is completely different from ASP in architecture, many of its built-in objects are also extended based on ASP. There are countless articles introducing ASP on the Internet, but few are introduced object-oriented and comparisons with other languages. This is why I decided to write this article.
Because it was an early version, ASP only provides very weak object-oriented interfaces. As we all know, the implementation languages of ASP are divided into VBScript and JavaScript/JScript: There is the Class keyword in VBScript, which can be used to declare a custom class; JavaScript is strange. It uses a function to "declare" the class, and then defines properties and methods in the function. Here we will discuss VBScript as the main topic. VBScript's class declaration is as follows:
Class name
statements
End Class
Here, public or private members can be declared in statements, including functions, members and attributes. Regarding properties, I have to praise Microsoft's get and set methods. This concept that appeared in COM has been used until .Net. I personally think that for programmers, it is much more convenient and intuitive to achieve the same effect than Java using getProp() and setProp() methods.
In contrast, classes in VBScript have their own advantages and those in PHP4 (of course they cannot be compared with the latest PHP5). Classes in VBScript maintain the incomplete object-oriented "characteristics" of VB. They only implement the most basic constructor/destructor, member functions, variables, attributes, and even constructors cannot take parameters. In PHP4, it also implements important properties of inheritance and function overloading. Only by implementing these can it be called object-oriented and can it be possible to provide a basis for implementing polymorphism. However, neither of them implements static members and other functions of the class. Although other workarounds can be used to achieve the same effect, this is not thorough from the perspective of object-oriented thinking (because PHP is very flexible, static variables of a class can be implemented indirectly through static variables of member functions in PHP4; while "::" - an operator that can implement static function access of a class - is not strictly checked in PHP4. In other words, all member functions can be accessed as static functions, and as long as you do not use member variables in that function, you will not make any mistakes. VBScript does not implement static at all, and can only be implemented with Session or Application). So in normal use, you can use VBScript's custom class to encapsulate some operations, but don't expect it to serve your object-oriented ideas like C++/Java/.Net.
VBScript also promotes the good style of default parameters or variables in VB being referenced. In this way, although Script is not sensitive to type, it can also achieve the same effect of pointers/references in C/C++, and accomplish many things. The most basic thing is, for example, using it to define a list (List) node class ListNode:
<%
Class ListNode
Public Content
Public NextNode
Private Sub Class_Initialize()
Content="Node"
Set NextNode=Nothing
End Sub
End Class
%>
Haha, it's that simple, but don't feel disdainful, and don't forget to have the initial value of the variable. It's almost the same in VB, just add the type when declaring it. When used:
<%
Set nh=new ListNode
Set =new ListNode
'Other statements...
'Travel the list
Set n=nh
While Not n is Nothing
+"<br />"
Set n=
Wend
%>
If no other code is added, the above run result is two "nodes". VBScript's custom classes and objects are not the same. As long as you master the basic concepts and have a certain understanding of them, it's simpler. Again, using Set statements to assign values to objects is equivalent to assignments in Java, and they all get a reference. This is much better than the default object assignment in PHP4 that calls the copy constructor to create a new object (even statements like obj=new Obj; will create two objects! If you want to get a reference, you need to add & before the variable after the equal sign), and it seems that PHP5 does not want to modify this approach in PHP4.
Session in ASP itself can store objects. It can save basic variables, arrays, automation objects, etc., but you will encounter problems when storing objects of custom classes. As shown in the following code:
<%
If isempty(Session("node")) Then Set Session("node")=New ListNode
Set n=Session("node")
%>
It is still the ListNode class above. This code intends to retain only one ListNode object in a user session. Therefore, when the user accesses the web page for the first time, an object of ListNode will be generated and saved in Session("node"); when accessing the web page later, because Session("node") is not empty, a new object will not be generated, but the saved object will be taken out in Session("node"). In theory, it should also output 100, but the problem is that ASP will keep reporting errors:
Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: ''
It will also make mistakes when used. The same code is translated into PHP, but it can be passed through. Why?
Personally, I believe that Session can save objects is correct, but the mechanism of type conversion in VBScript is too weak, and there is no explicit cast type conversion for users to use, so Session("node") cannot be correctly converted to ListNode type. Because it is a custom class, we can only appear class definition statements in each page. In this way, in the view of ASP, every time we read this page, the ListNode class is a new class, so we do not recognize the object of this class in the Session.
Conclusion: Try not to use Session or Application to store objects of custom classes in ASP. If you really need it, you can consider writing classes with COM, and then use: Set Session("obj") = ("") in VBScript to create an object, and then you can implement the functions expected above.
Keywords ASP object-oriented programming discussion and comparison
Source
ASP is a dynamic web programming technology launched by Microsoft in the early days, but it combines ADO's convenient and fast access to databases, combined with other technologies such as XML, COM/ActiveX to realize the multi-layer structure of the server, which has strong vitality today and still has certain developments. Although it is completely different from ASP in architecture, many of its built-in objects are also extended based on ASP. There are countless articles introducing ASP on the Internet, but few are introduced object-oriented and comparisons with other languages. This is why I decided to write this article.
Because it was an early version, ASP only provides very weak object-oriented interfaces. As we all know, the implementation languages of ASP are divided into VBScript and JavaScript/JScript: There is the Class keyword in VBScript, which can be used to declare a custom class; JavaScript is strange. It uses a function to "declare" the class, and then defines properties and methods in the function. Here we will discuss VBScript as the main topic. VBScript's class declaration is as follows:
Class name
statements
End Class
Here, public or private members can be declared in statements, including functions, members and attributes. Regarding properties, I have to praise Microsoft's get and set methods. This concept that appeared in COM has been used until .Net. I personally think that for programmers, it is much more convenient and intuitive to achieve the same effect than Java using getProp() and setProp() methods.
In contrast, classes in VBScript have their own advantages and those in PHP4 (of course they cannot be compared with the latest PHP5). Classes in VBScript maintain the incomplete object-oriented "characteristics" of VB. They only implement the most basic constructor/destructor, member functions, variables, attributes, and even constructors cannot take parameters. In PHP4, it also implements important properties of inheritance and function overloading. Only by implementing these can it be called object-oriented and can it be possible to provide a basis for implementing polymorphism. However, neither of them implements static members and other functions of the class. Although other workarounds can be used to achieve the same effect, this is not thorough from the perspective of object-oriented thinking (because PHP is very flexible, static variables of a class can be implemented indirectly through static variables of member functions in PHP4; while "::" - an operator that can implement static function access of a class - is not strictly checked in PHP4. In other words, all member functions can be accessed as static functions, and as long as you do not use member variables in that function, you will not make any mistakes. VBScript does not implement static at all, and can only be implemented with Session or Application). So in normal use, you can use VBScript's custom class to encapsulate some operations, but don't expect it to serve your object-oriented ideas like C++/Java/.Net.
VBScript also promotes the good style of default parameters or variables in VB being referenced. In this way, although Script is not sensitive to type, it can also achieve the same effect of pointers/references in C/C++, and accomplish many things. The most basic thing is, for example, using it to define a list (List) node class ListNode:
<%
Class ListNode
Public Content
Public NextNode
Private Sub Class_Initialize()
Content="Node"
Set NextNode=Nothing
End Sub
End Class
%>
Haha, it's that simple, but don't feel disdainful, and don't forget to have the initial value of the variable. It's almost the same in VB, just add the type when declaring it. When used:
<%
Set nh=new ListNode
Set =new ListNode
'Other statements...
'Travel the list
Set n=nh
While Not n is Nothing
+"<br />"
Set n=
Wend
%>
If no other code is added, the above run result is two "nodes". VBScript's custom classes and objects are not the same. As long as you master the basic concepts and have a certain understanding of them, it's simpler. Again, using Set statements to assign values to objects is equivalent to assignments in Java, and they all get a reference. This is much better than the default object assignment in PHP4 that calls the copy constructor to create a new object (even statements like obj=new Obj; will create two objects! If you want to get a reference, you need to add & before the variable after the equal sign), and it seems that PHP5 does not want to modify this approach in PHP4.
Session in ASP itself can store objects. It can save basic variables, arrays, automation objects, etc., but you will encounter problems when storing objects of custom classes. As shown in the following code:
<%
If isempty(Session("node")) Then Set Session("node")=New ListNode
Set n=Session("node")
%>
It is still the ListNode class above. This code intends to retain only one ListNode object in a user session. Therefore, when the user accesses the web page for the first time, an object of ListNode will be generated and saved in Session("node"); when accessing the web page later, because Session("node") is not empty, a new object will not be generated, but the saved object will be taken out in Session("node"). In theory, it should also output 100, but the problem is that ASP will keep reporting errors:
Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: ''
It will also make mistakes when used. The same code is translated into PHP, but it can be passed through. Why?
Personally, I believe that Session can save objects is correct, but the mechanism of type conversion in VBScript is too weak, and there is no explicit cast type conversion for users to use, so Session("node") cannot be correctly converted to ListNode type. Because it is a custom class, we can only appear class definition statements in each page. In this way, in the view of ASP, every time we read this page, the ListNode class is a new class, so we do not recognize the object of this class in the Session.
Conclusion: Try not to use Session or Application to store objects of custom classes in ASP. If you really need it, you can consider writing classes with COM, and then use: Set Session("obj") = ("") in VBScript to create an object, and then you can implement the functions expected above.