Page 227 - DCAP408_WEB_PROGRAMMING
P. 227
Unit 9: ASP Objects
Now that we have a way of describing the telephone object, let’s take a look at what we can do Notes
with it.
Methods
Another characteristic of objects is that they can perform functions for us. For example, the Place
Call method would perform several functions for you. It will connect you to the local exchange,
the exchange will route your call, and then when it reaches the destination, and it will make the
destination phone ring. These built-in actions occur whenever you pick up the handset and dial
a number. This is a capability that has been built in to the machine.
However not all objects have functions like this. A chair object allows you to sit in it, so you
could say that it is functioning to support your body. Objects that perform tasks that are more
‘functional’ are said to have methods. The tasks that an object can perform are called methods.
A method is defined as an action that an object can take. The code in a method is executed when
the method is called. This calling is done by a command you write in the script of your ASP page.
Once we have created an instance of an object, we can tell it to perform a certain task calling one
of its methods.
Let’s illustrate this using the telephone example. Our telephone object can carry out five methods.
Each of these methods will cause the telephone object to perform an action. Here is a list of
functions that the methods of the telephone object can perform:
These methods are used when we want our telephone object to perform a certain function; all we
need to do is tell it to execute the corresponding method.
Methods are actually blocks of code that are written by the designer of the object (Microsoft, for
example).
Did u know? What is the reason of method existing?
The reason methods exist is because lots of programmers want to do the same job, so it is
worth it for the gurus at Microsoft to write the code to do that job, test it, optimize it, and
get it in great shape, and then bundle it up in the object.
We, as programmers, can then use that code pre-made. Instead of re-inventing the wheel we
spend our time on the unique parts of our project.
Self Assessment
Fill in the blanks:
1. When a specific instance of an object is created from the ………………….. for the object, the
object is said to have been instantiated.
2. A new instance of the object may have different property values, but it has the same
…………………..
3. A method is defined as an action that an ………………….. can take.
4. The properties of an object are used to represent a set of ………………….. associated with
the object.
LOVELY PROFESSIONAL UNIVERSITY 221