In this article we will look some very nice features provided by Asp.net ajax library.
create closures and prototype.
ClosureA closure is a function that encapsulates a
To access class members we can create object of the class
just like we do for any other oop language.
PrototypePrototype is another approach for designing
Using prototype method we can design classes as below
Now we have seen the prototype method of declaring a
class. Object creation, accessing members is same as that of seen for closure.
one might ask what is the difference between
closure method and prototype method? Answer is, closure creates members for
your object every time it is created but for prototype members are created only
once and then simply copied in each n new object. Hence performance wise prototype
method is more suitable.
Working With Asp.Net Ajax Library
ASP.Net ajax provide some very useful
features for supporting object oriented development.Using these features we can
- Create classes
- Create interfaces
- Inherit classes and interfaces
- Use reflections
And much more. Here I will write few basic
things which I have studied and which you find as a basic for learning Ajax
Registering Class with Asp.Net Ajax library
prototype approach. Now we have to register this class with Ajax library. How
to do that?For doing this first we need to include
ASP.Net Ajax control named ScriptManager
our page.(Its just drag and drop from control
libraries for you. Now care must be taken for whatever code we will write it
should be written below the script Manager.
For registering class we use registerClass()
After this step your class is registered with Asp.net
Ajax library and can now use inbuilt features provided by Ajax framework like
This will return you a fully qualified name of a
class the object belong to. Additional methods are listed below
Creating And Registering Namespace
To register a namespace we use Type.registerNamespace()
Here if you apply Object.getTypeName()
function on object obj then it will return
fully qualified name i.e.
Inheritance can be achieved using registerClass()
= fully qualified name of class baseType
= this is optional parameter. Base class
= this is optional parameter.(see
it is types not type). Interface name.
if more than one then separate names
This can be best understood using an example.
allow us to implement a common set of methods across multiple classes with less
room for error.
Below example shows an interface "IShape" which contain an abstract method
named drawShape().I have created IShape interface and a class Circle which
implement the interface.
After creating an interface we need to
register it with clientside ajax library using registerInterface()
method.(last code line)
to implement an interface first give implementation for its method(s) and then
inherit the class from interface in registerClass() method.
null parameter in registerClass() in above code indicate
that there is no base class for this class.
if you run the code you will get the following output
Creating enum types with ajax library is very simple.
first create enum and the register it with ajax library using Type.registerEnum()
method. Look at below example where Enum named color is created and registered
with Ajax library