However, if the class is used less, it is only a big module packaging method. only by using it for large-scale development can it demonstrate its superiority in project management. the so-called pasta Style Code It will end with ASP.
I think most of the current ASP Program I am not familiar with the terms of object-oriented programming. I need to add a chapter to describe the roles of classes in ASP and Their Relationships with object-oriented programming.
I will try to explain the use of class in a way that is close to programming practices, but will not use abstract terms such as object-oriented. If you have the theoretical basis of object-oriented, you can combine the content or discover it uniquely. if you have never understood object-oriented, you don't have to know what object-oriented is, as long as you read this series Article , Learned the usage of class, and in the programming process according to the rules, you can be robust enough to manage your ASP code.
Class is equivalent to a packing box, which can wrap variables and functions to form a whole. All the content to be discussed in this series can be said to be the knowledge of packaging.
For example, we can wrap a class for mathematical processing and use it:
Copy code The Code is as follows: Class con_math
Public
Public B
Private intc
Public Function sum ()
Intc = CINT (A) + CINT (B)
Sum = intc
End Function
End Class
Set math = new con_math
Math. A = 19
Math. B = 80
Response. Write math. Sum
Set math = nothing
Line-by-line explanation Syntax:
1. Define a Packing Box named con_math. Everyone knows that math is a mathematical meaning. Con _ prefix is my programming habit. For classes that may be used in the entire program, A con _ prefix indicates a general class. it is purely a programming habit, but adding a prefix is not only a habit problem, but will be explained later.
2, 3 put two variables, named A and B. The public variables in front of them indicate that they are public variables and can be accessed by external programs.
4. The variable intc is defined as private, indicating that it is the private variable inside the packing box. It cannot be seen from the outside or forcibly pulled out, no matter how powerful you are. steal it? Try it.
Rows 6, 7, 8, and 9 define a function for addition operations. Except for a public function, everything else is what you use every day. If you are not familiar with it ...... let's just look at this series. It's better to do basic homework first. like the two variables above, adding a public variable indicates that a hole is opened in the packing box. You can see it from the outside and use it.
10 end class is packed with packing tape, and a neat class is packed.
However, this packing box is just an idea and cannot be used as a ready-to-use box. to borrow the words of Master Tang MIAO: (Wukong wants to eat me) it is just an idea that has not yet become a reality (what is his sin?). It is better to wait until it is instantiated, it's not too late to use it again (It's not too late to count on him again ).
Instantiation indicates the actual eating behavior.
We can easily instantiate our ideas in ASP code. Unfortunately, thousands of monsters on the westday road have no way to instantiate their class "Eat Tang and Monk". It's really cool!
This is the superiority of programmers.
12. If we instantiate the defined class, the instantiation name cannot be exactly the same as the conception name, otherwise it will be messy in terms of syntax. so now everyone knows, why is the habit of adding a prefix to the class? Of course, you do not need to use con _ as the prefix. The following are all good materials: Yaomin _ jimo _ chunge _...... or you can use your wife's nickname. You have to live with imagination.
We assign values to the two open variables A and B. as you can imagine, it is a hole in the packing box. Through this hole, you can put things in and take them out. must pass through this hole. hmm? Too small? No, don't worry. Anything big can be put in, just like a human's mouth. Although small, food as big as the Earth can be eaten.
15 through the small hole, we took out the function operation result and displayed it on the page, 99, Geely. This is the number of the first two and the last two of my years of birth. open a notepad, write this code, and run it in IIS.
16. The gay man needs to wash the dishes and wash the pot after dinner at home. set ** = nothing is the same. this is the same as clearing the recordset after it is created. after set nothing, it indicates that it is discarded from the memory. The location occupied by this universal packing box is empty. Of course, your website performance will improve. What do you hesitate to do? Run out and set nothing.
I know that everyone won't play the function like this. At least sum () makes it easier to use. Well, let's make another hole in the packing box:Copy codeThe Code is as follows: Class con_math
Public
Public B
Private intc
Public Function sum ()
Intc = CINT (A) + CINT (B)
Sum = intc
End Function
Public Function sum2 (byval va, byval VB)
Sum2 = CINT (VA) + CINT (VB)
End Function
End Class
Set math = new con_math
Response. Write math. sum2 (19,80)
Set math = nothing
Do you still want to Ctrl + C?
Although you look at me with such sincerity, you still want to say whether you want to learn. If you don't want to learn, I want to learn from you, do you really want to learn? OK?
Do not press Ctrl + C.