ASP uses class _asp classes in ASP using three-tier architecture

Source: Internet
Author: User
But class this thing, if used relatively little, at best, is a large module packaging mode. Only by using it on a large scale can we show its superiority to project management. The so-called Spaghetti code, and ASP will be a full stop.
I think most of the ASP programmers have not yet used class, not very familiar with object-oriented terminology, need to add a chapter to describe the ASP's role in the class, as well as the relationship between object-oriented programming.
I will explain the use of class in ways that are as close to programming practice as possible, but without using abstract terminology such as object-oriented, if you have an object-oriented rationale, you can combine these elements or have your own unique discoveries. If you don't know the object-oriented, you don't have to be aware of what's going on, as long as you learn the use of class by reading this series of articles, and by the rules in programming, you can manage your ASP code well enough.
Class equivalent to a box, it can be a variable and function packaging to form a whole, this series of articles to talk about all the content, it can be said that the knowledge of packaging.
For example, we can wrap a math-processing class and use it:
Copy Code code as follows:

Class Con_math
Public A
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

To interpret syntax line by row:
1, the definition of a box, named Con_math, we all know that math is the meaning of mathematics, Con_ prefix is my programming habits, for the entire program may be used in class, crown a con_ prefix, representing it is a universal class. It's purely a programming habit, but adding a prefix is not just a matter of habit, it will be explained later.
2,3 put in 2 variables, named A,b, whose front public represents them as common variables that can be accessed by outside programs.
The 4 variable INTC is defined as private, which means that it is a proprietary variable inside the box and cannot be seen from the outside or forcibly pulled out, no matter how much effort you have. Steal it?
6,7,8,9 these four lines define a function to perform the addition, except for one public, and the other is what you use every day, if you don't look familiar ... Or do not look at this series, the first to do basic homework better. As with the two variables above, add a public indication that the box opens a hole here and you can see it from the outside and use it.
Ten end class with a sealed box of tape, a neat class on the packaging completed
But, this box is only a concept, can not be used as ready-made. Tang's monk to borrow the words of the master: (Wukong He wants to eat me) is just a concept, has not become a reality (he is what the crime of it), as well as it after the instantiation, and then use is not late AH (and then set his sins not late AH).
The actual meat eating behavior is represented by the instantiation.
We can easily instantiate our ideas in the ASP code, but the west of the road thousands of monsters have no way to instantiate their "eat Tang" class, really can be pitied!
This is the advantage of programmers.
12 instantiation of our defined class, instance aliases can not be the same as the idea name, otherwise the grammar will be messy. So now that you know, why would you give Class A prefix? Of course, everyone can do without con_ prefix, and so on are good materials: Yaomin_ jimo_ Chunge_ ... Or you can use your wife's girlfriends, and people have to live with a little imagination.
13,14 We assign the two variables that are exposed to a,b, here's the. Number, you can imagine it is a hole in the box, through this hole, you can put things in and take out. You must pass through this hole. Yes? Is it too small? No, don't worry, anything bigger can be put in. Like a man's mouth, Small as it is, the Earth's large food can be eaten up.
15 we get through the small hole, the function of its operation results out, displayed on the page, 99, auspicious ah, this is my birth year's top two and the last two digits add the number. Open a Notepad, write the code, and run it in IIS.

16 male comrades at home after dinner, is to wash the dishes and wash the pot. Set * * = Nothing is the same thing. This is the same usage as clearing the recordset after it is created. Set nothing after that it is discarded from the memory, this universal box occupies the position of the empty, your site will certainly improve performance, but also hesitate what? Ran out hurriedly set nothing.
I know we're not going to do this. function, at least sum (19,80) is more convenient to use, OK, we have another hole in the box to come out:
Copy Code code as follows:

Class Con_math
Public A
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

You still want to CTRL + C?
Although you look at me so sincerely, but you still want to say is not want to learn, can not you do not want to learn I biased to you to learn, also can not you want to learn I do not let you learn, do you really want to learn?
Then don't CTRL + C.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.