Using classes in ASP to achieve modularity

Source: Internet
Author: User
Tags define object end inheritance variables string trim
First of all, I want to write some very official concepts here to illustrate that object-oriented is very concrete, very solid mode, not to let some people see "object" is scared away.

Objects are things you can see, feel, hear, touch, taste, or smell, and here we are "defined": an object is a self-contained entity that is identified by a set of identifiable attributes and behaviors.
In object-oriented programming (OOP), use the following two terms.
Class: This is the template for the object, which defines the attributes of the object.
Example: This is a real object that can interact with it.

Properties, methods, and events

In OOP, the following term describes the attributes of an object
Attribute: This is a ranking that describes the properties of an object
Method: This is a verb that describes the work that an object can accomplish, or the work it is expected to accomplish.
Events: Describes the actions that an object performs for a corresponding action.
In programming, objects are part of object-oriented programming and object-oriented design, they have great advantages, many people think this is a complex topic, but in fact, it is very simple, can be explained in four simple terms: abstraction, encapsulation, polymorphism and inheritance.
Abstract: This is a hidden complexity, the internal workings of the class, so the user does not have to know how it works, just like. If you want to watch TV, you don't have to know how to work the TV, just turn on the TV, search the channel, the On/off switch abstracts the actual operation, in the string example, there is a trim method, it can delete the string trailing spaces, also do not need to know how he completed the task, Just know that it has this function.

Encapsulation: Each object contains all the information that is required for the operation, which is called encapsulation, so that the object does not perform its own operation more than relying on other objects, and in the term ToUpper () method, a string does not have to get information elsewhere to convert all characters to uppercase.

Polymorphism: This term is used to indicate that different objects can perform the same actions, but by their own implementation code to execute, the name is the same, but the underlying implementation of the code is not the same.

Inheritance: It defines how classes relate to each other, share attributes, inheritance works by defining classes and subclasses in which subclasses inherit all the attributes of the parent class, and the importance of inheritance is that it forces a class of similar types to be consistent and allows sharing of code, and if you decide to create a new class, you do not have to define all the attributes of the parent class. Let me take a few simple examples to illustrate, note that here is an emphasis on the idea that it is necessary (and difficult) to expand an ASP site with a class (base class).

Let's first choose a simple example:

We want to display the information of the Classic forum users, when you enter the user ID can, display some information about the user, this is a process, you can consider this, we regard the user as an object, he has attributes are ID, gender, integration, permissions, the implementation of the method has to display this information, OK, so write:

Class Blueidea
Private Bname,bpoint,bsex,blevel
End class here first declares a class named Blueidea, followed by some private variables to store the properties of the Blueidea class, which are not accessible outside the code, which is data protection, to define these variables, The property statement is used to get the value to be paid indirectly to the private variable. ...
Property Get GetName
End Property

Property Let GetName (NameID)
If nameid= "" Then
Bname= "Not registered users"
End If
End Property
Property Get Getsex
End Property

Property Let Getsex (Sex)
Bsex=killint (sex,0,0)
If bsex=0 Then
bsex= "Male"
bsex= "Female"
End If
End Property
Property Get GetPoint
End Property

Property Let GetPoint (Point)
Bpoint=killint (point,0,0)
End Property

Here is a killint function, which is to judge the legality of data, and its original form is: Private function Killint (i,killstr,killsub)
If not IsNumeric (i) Then
ElseIf i<=0 Then
End If
Killint=int (Left (i,5))
End Function

The function is clear and no longer tedious to say.

Because we want to judge the user level by integral, here is a private function defined: Private functions Getlevel ()
        bpoint= Killint (bpoint,0,0)
        If bpoint<500 Then
         blevel= "junior member"
        ElseIf bpoint>=500 and      bpoint<=100 Then
        blevel= "senior member"
        blevel= "Ultimate Member"
        End If
        End Function We need to be loopback user information, must define a public common function, display information:

Public Function Showuser ()
        Response.Write ("         Response.Write ("          Response.Write ("         getlevel
         Response.Write ("         End Function
End Class

Use this class when using this: (I wrote a form here to handle it)
Set blueideauser=new Blueidea
Blueideauser.getname=trim (Request ("id"))
Blueideauser.getsex=request ("Sex")
Blueideauser.getpoint=request ("point")

Related Article

Alibaba Cloud 10 Year Anniversary

With You, We are Shaping a Digital World, 2009-2019

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.