I will probably be at the TechED this year also (Barcelona), so I hope to see some of you there. I think this year’s TechED will ROCK! At the moment I’m working on some Silverlight screen caps, at the moment they are only in Swedish. I have tried VS 2008 Beta 2 for a while and it have never crashed for me yet, so if some of you wonder if it’s stable. Well I think so. I did have some problems with my old VS 2005 on the same machine (Yes, I know. I should have used Virtual PC, but I wanted to try to see how beta 2 and VS 2005 would work on the same machine). Now to some AJAX stuff.
In this post I’m going to show you how you can use Interfaces in Java-script with ASP.Net AJAX Client Library. As you may know java-script don’t support interfaces, but ASP.Net AJAX made it possible ;)
The following code is n interface:
Nsquared2.ICustomer = function()
{
throw Error.notImplemented();
}
Nsquared2.ICustomer.prototype =
{
get_firstName: function()
{
throw Error.notImplemented();
},
get_lastName: function()
{
throw Error.notImplemented();
}
}
Nsquared2.ICustomer.registerInterface('Nsquared2.ICustomer');
As you can in the code above, we actually define an Interface in a similar way as we create a Class with the ASP.Net AJAX Client Library. The only different here is the registerInterface method that will register our interface to be used as an interface. To make sure no one should use the ICustomer as a class, we throw a notImplemeted exception. The ASP.Net AJAX Client Library has an Error object with different kind of pre-defined exception that we can use; the notImplemented is one of them.
To use the interface we simply make sure our class implements the method in the interface, in this case the get_firstName and get_lastName:
Nsquared2.Customer.prototype =
{
...
get_firstName: function()
{
//Implement the method body here
},
get_lastName: function()
{
//Implement the method body here
}
}
Note: You can read about how to create a class in my post Create a "class" (type) in Java-Script by using the ASP.Net Ajax Library
When our class in created we pass the interface to the registerClass method of our class to make sure it will use the interface:
Nsquared2.Customer.registerClass('Nsquared2.Customer', null, 'Nsquared2.ICustomer');
Note: The registerClass method is explained in my previous posts about creating classes.