<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Sohail Sayed</title><link>http://weblogs.asp.net/sohailsayed/default.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Debug Build: 20510.895)</generator><item><title>Calling methods in a codebehind function (PageMethods) from client side using ajax.net</title><link>http://weblogs.asp.net/sohailsayed/archive/2008/02/23/calling-methods-in-a-codebehind-function-pagemethods-from-client-side-using-ajax-net.aspx</link><pubDate>Sat, 23 Feb 2008 18:29:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5845803</guid><dc:creator>ssayed@iotap.com</dc:creator><slash:comments>19</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/sohailsayed/rsscomments.aspx?PostID=5845803</wfw:commentRss><comments>http://weblogs.asp.net/sohailsayed/archive/2008/02/23/calling-methods-in-a-codebehind-function-pagemethods-from-client-side-using-ajax-net.aspx#comments</comments><description>&lt;p mce_keep="true"&gt;Hi,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Everyone using ajax.net will be familiar with the updatepanels. In addition another well known way of utilizing the rich ajax.net library is calling web service methods or methods from the code behind file from&amp;nbsp;the client side. Recently i came across a situation in my project where i wanted to call methods from code behind (i have been using updatepanels but in some situation all i was doing was getting few values from the db and i felt not using the updatepanel would be a better option rather calling the my code behind function using pagemethods feature would be more appropriate). Though&amp;nbsp; there is a good deal of information on the internet on update panels and calling web services i found it difficult to&amp;nbsp;reach a good enough article showing me how to call a function from the codebehind file.&amp;nbsp; Finally though :-) i was able to call the code behind function. i am going to demonstrate the same in this blog.&lt;br&gt;&amp;nbsp;&amp;nbsp; Before starting let me indicate there could be&amp;nbsp;many reasons for calling code behind methods from client side using ajax.net .....in my case i wanted to use existing functionality in my code behind and we were not using any webservices .&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp; Here i am going to demonstrate a simple&amp;nbsp;&amp;nbsp; application that calls a code behind method&lt;br&gt;&lt;br&gt;to start first we create an ajax enabled website. Then in our page we add the heart of ajax.net -- the ScriptManager control and set the EnablePageMethods property as true&lt;br&gt;&lt;br&gt;&lt;font color="#0000ff" size="2"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000" size="2"&gt;ajax&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;:&lt;/font&gt;&lt;font color="#800000" size="2"&gt;ScriptManager&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;ID&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;="ScriptManager1"&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;runat&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;="server"&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;EnablePageMethods&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;="true"&amp;gt;&lt;/font&gt;&lt;br&gt;&lt;br&gt;We also place a div and input buttons on our form&lt;br&gt;&lt;br&gt;&lt;font color="#0000ff" size="2"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000" size="2"&gt;div&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;id&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;="div1"&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;font size="2"&gt;
&lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#800000" size="2"&gt;div&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;font size="2"&gt;
&lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000" size="2"&gt;input&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;type&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;="button"&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;value&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;="Call Page Method With No Parameters"&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;onclick&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;="CallPageMethod()"&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;/&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;font size="2"&gt;
&lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#800000" size="2"&gt;input&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;type&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;="button"&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;value&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;="Call Page Method With Parameters"&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;onclick&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;="CallParametersPageMethod()"&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;/&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;font size="2"&gt;
&lt;/font&gt;&lt;p mce_keep="true"&gt;&lt;font size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;/p&gt;
&lt;p mce_keep="true"&gt;As the text indicates on call a&amp;nbsp;function without parameters and the other calls a function having parameters&lt;/p&gt;The code behind function are as below&lt;br&gt;&lt;br&gt;&lt;font size="2"&gt;[System.Web.Services.&lt;/font&gt;&lt;font color="#008080" size="2"&gt;WebMethod&lt;/font&gt;&lt;font size="2"&gt;()]&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;static&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; MyFirstPageMethod()&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#800000" size="2"&gt;"Welcome to the world of AJAX.NET "&lt;/font&gt;&lt;font size="2"&gt; ;&lt;br&gt;}&lt;/font&gt;&lt;font size="2"&gt; &lt;br&gt;&lt;br&gt;[System.Web.Services.&lt;/font&gt;&lt;font color="#008080" size="2"&gt;WebMethod&lt;/font&gt;&lt;font size="2"&gt;()]&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;static&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; MyFirstParameterPageMethod(&lt;/font&gt;&lt;font color="#008080" size="2"&gt;String&lt;/font&gt;&lt;font size="2"&gt; strVal)&lt;br&gt;{&lt;br&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;nbsp;&amp;nbsp; return&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#800000" size="2"&gt;"Welcome to the world of AJAX.NET , the value you passed is : "&lt;/font&gt;&lt;font size="2"&gt; + strVal ;&lt;br&gt;}&lt;/font&gt;&lt;font size="2"&gt; 
&lt;/font&gt;&lt;p mce_keep="true"&gt;To call a page method it must be static and you have to mark it with the WebMethod attribute. The first function doesnot takes parameter while the second function takes a string value as parameter. both return a string value.&lt;br&gt;&lt;br&gt;&amp;nbsp;The javascript function are as below&lt;br&gt;&lt;br&gt;&amp;lt;&lt;font color="#800000" size="2"&gt;script&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;language&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;="javascript"&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;function&lt;/font&gt;&lt;font size="2"&gt; CallPageMethod()&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PageMethods.MyFirstPageMethod(onSucceeded,onFailed);&lt;br&gt;}&lt;/font&gt;&lt;font size="2"&gt; 
&lt;/font&gt;&lt;p mce_keep="true"&gt;&lt;font color="#0000ff" size="2"&gt;function&lt;/font&gt;&lt;font size="2"&gt; CallParametersPageMethod()&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp; PageMethods.MyFirstParameterPageMethod(&lt;/font&gt;&lt;font color="#800000" size="2"&gt;"This is a Demo"&lt;/font&gt;&lt;font size="2"&gt;,onSucceeded,onFailed);&lt;br&gt;}&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;function&lt;/font&gt;&lt;font size="2"&gt; onSucceeded(result,userContext,methodName)&lt;br&gt;{&lt;br&gt;&amp;nbsp; $get(&lt;/font&gt;&lt;font color="#800000" size="2"&gt;'div1'&lt;/font&gt;&lt;font size="2"&gt;).innerHTML=result;&lt;br&gt;&lt;/font&gt;&lt;font size="2"&gt;}&lt;/font&gt;&lt;font size="2"&gt; 
&lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;function&lt;/font&gt;&lt;font size="2"&gt; onFailed(error,userContext,methodName)&lt;br&gt;{&lt;br&gt;&amp;nbsp; alert(&lt;/font&gt;&lt;font color="#800000" size="2"&gt;"An error occurred"&lt;/font&gt;&lt;font size="2"&gt;)&lt;br&gt;}&lt;/font&gt;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#800000" size="2"&gt;script&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; 
&lt;/font&gt;&lt;p mce_keep="true"&gt;The&amp;nbsp;CallPageMethod method calls the parameterless function MyFirstPageMethod&amp;nbsp;from codebehind and the CallParametersPageMethod&amp;nbsp;calls the code behind function MyFirstParameterPageMethod&amp;nbsp;and passes a string as parameter&amp;nbsp;&amp;nbsp;&lt;br&gt;&lt;br&gt;We call the codebehind method as PageMethods.MethodName();&lt;br&gt;&lt;br&gt;The OnSucceeded parameter indicates&amp;nbsp;the javascript function to be called when the call has succeeded and the result parameter has the result stored in it in our case the&amp;nbsp;string returned from the code behind file.&lt;br&gt;&lt;br&gt;The OnFailed&amp;nbsp;parameter indicates the&amp;nbsp;javascript function to be called when&amp;nbsp; error occurs.&lt;br&gt;&lt;br&gt;In case the code behind function has no parameters then&amp;nbsp;we pass the onSucceeded and OnFailed parameters only.&lt;br&gt;&lt;br&gt;To pass a parameter to code behind we pass them in the same order as the code behind function and at the end we add the&amp;nbsp;onsucceeded and onfailed&amp;nbsp;parameters as in the CallParametersPageMethod&amp;nbsp;javascript function.&lt;br&gt;&lt;br&gt;The return value is displayed in the div.&lt;br&gt;&lt;br&gt;I have attached the complete code&amp;nbsp;of this.&lt;br&gt;&lt;br&gt;Hope&amp;nbsp;this is helpful to you all.&lt;br&gt;&lt;br&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5845803" width="1" height="1"&gt;</description><enclosure url="http://weblogs.asp.net/sohailsayed/attachment/5845803.ashx" length="4544" type="application/x-zip-compressed" /><category domain="http://weblogs.asp.net/sohailsayed/archive/tags/asp.net/default.aspx">asp.net</category><category domain="http://weblogs.asp.net/sohailsayed/archive/tags/code+behind+functions/default.aspx">code behind functions</category><category domain="http://weblogs.asp.net/sohailsayed/archive/tags/Ajax.net/default.aspx">Ajax.net</category><category domain="http://weblogs.asp.net/sohailsayed/archive/tags/codebehind+functions+ajax.net/default.aspx">codebehind functions ajax.net</category><category domain="http://weblogs.asp.net/sohailsayed/archive/tags/PageMethods/default.aspx">PageMethods</category><category domain="http://weblogs.asp.net/sohailsayed/archive/tags/.NET/default.aspx">.NET</category></item><item><title>Inheritance, Abstract classes and Interfaces</title><link>http://weblogs.asp.net/sohailsayed/archive/2008/01/23/inheritance-abstract-classes-and-interfaces.aspx</link><pubDate>Wed, 23 Jan 2008 19:49:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5640777</guid><dc:creator>ssayed@iotap.com</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/sohailsayed/rsscomments.aspx?PostID=5640777</wfw:commentRss><comments>http://weblogs.asp.net/sohailsayed/archive/2008/01/23/inheritance-abstract-classes-and-interfaces.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;Hi,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C++ was one of the first language i learnt and along with that i learnt the OOPs concept of inheritance. It was pretty simple and confusing at the same time (multiple inheritance concept&amp;nbsp;saw me putting a lot of efforts in&amp;nbsp;:-) ). However life became simpler with multiple inheritance eliminated in .Net. However came the new concept of interfaces in .Net. For a long time i couldnt get the understanding of when to use interfaces and when to use abstract classes. Things became much clearer later, though i have seen this topic remains a big confusion for a lot of people (atleast&amp;nbsp; i have seen this in my friend circle and also in lot of posts). I am writing on this topic as my first blog, and i hope it will help to make things related to interface and abstract classes clearer.&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Let us first look at the concept of inheritance.&amp;nbsp;This has come up as a wonderful concept and one of the best methods to enable code reusability in the OOPs world. Let me give an example as how inheritance can be useful.&amp;nbsp;For this let me give an example of the class System.Web.UI.Page class.&amp;nbsp;&amp;nbsp;For those who have worked on asp.net this will be the most familiar class. This is a built in asp.net class that contains a lot of basic funcitonality related to a Web page. Now&amp;nbsp;to create the simplest web page all i have to do is to create a class that inherits from the System.Web.UI.Page class ... and&amp;nbsp;here you go ... my web page is ready ..though we may need&amp;nbsp;to add&amp;nbsp;some stuff to make it more meaningful. But once you inherit from this class you get access to a lot of objecft like response, request, server , and also lot of utility methods and events (you will find the list of &amp;nbsp;all the methods and events on the microsoft msdn website).[1].&amp;nbsp;This is the simplest example of&amp;nbsp;the use of inheritance.&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp; Let me show you another example of the advantage of inheritance. In one of our projects We had to implement a lot of functionality related to formatting, localization and also performance tracking.&amp;nbsp;We had to do custom formatting of data like currency , date and also numeric fields. For this we created our own controls that inherited from standard .Net controls. to be more specific let me&amp;nbsp;show you the example of currency textbox and datetextbox.&amp;nbsp;In our application we have to show currency formatted in a specific manner.&amp;nbsp;Rather than formatting each and every textbox manually we create control that inherited from the asp.net Textbox control and&amp;nbsp;formatted&amp;nbsp;the&amp;nbsp;content in that inherited control. This&amp;nbsp;is shown below (this is a rough example, kindly ignore any syntax or casing errors) - &lt;BR&gt;&lt;BR&gt;&amp;nbsp; public class CurrencyTextBox&amp;nbsp;: Textbox&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&amp;nbsp;shadows property&amp;nbsp;Text() as string&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return unformat( mybase.text) 'unformat will convert the formatted text to normal mumeric value&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set (value as string)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mybase.text= format(value) 'format the&amp;nbsp;numeric value to proper&amp;nbsp;currency format&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end set&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end property&lt;BR&gt;&amp;nbsp; end class&lt;BR&gt;&lt;BR&gt;another example for datetextbox&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public class DateTextBox:&amp;nbsp;TextBox&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&amp;nbsp;sub&amp;nbsp;onLoad()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;me.attributes.add("onclick","showDateCalendar()") 'add attribute to show claendar when user clicks on textbox&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end sub&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end class&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;using the above code i got the rid&amp;nbsp;of taking care of formatting each control individually or adding attributes to each individual datetextboxes.&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Another&amp;nbsp;example of inheritance i can tell is having a&amp;nbsp;custom base class for all my base forms.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;We have a base class that itself inherits from System.Web.UI.Page class and all my&amp;nbsp;webforms inherit from this class. We have put all common functionality in this base class and avoided repeating a lot&amp;nbsp;of code&amp;nbsp;that would have been otherwise written in each&amp;nbsp;of the individual web forms.&amp;nbsp;In addition to all these when&amp;nbsp;ever we want to add any common functionality to all the web forms we need to add it to only the base&amp;nbsp;class.&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; I hope from here you can start appreciating the value of inheritance if you havent been earlier. Now let me go into&amp;nbsp;abstract classes.&amp;nbsp;In some cases we&amp;nbsp;have a&amp;nbsp;base class, but some times few functions of it it can not be defined fully.&amp;nbsp;The simplest and perhaps&amp;nbsp;a common example will be the&amp;nbsp;class Shape which can be classified as the base class&amp;nbsp;for&amp;nbsp;the class Rectangle and class Circle. Every shape has area and volume. We cannot however define&amp;nbsp;the functions related to them&amp;nbsp;in the class&amp;nbsp;Shape (the functions can be called -- CalculateArea , CalculateVolume). We just declare these functions and not define their implementation. Such functions are called as abstract functions[2]. And the classes that contain them get called as abstract classes.&lt;BR&gt;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; Interfaces are a special&amp;nbsp;case&amp;nbsp;where all the functions are abstract. The advantage of interfaces is that&amp;nbsp;they enable in a way multiple inheritance.[3].&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; Now comes the big confusion .. When to use interfaces and when to use&amp;nbsp;base classes/ abstract base classes&amp;nbsp;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; A base class would normally represent a more generalized version of its child type like a furniture as a generalized&amp;nbsp;type of chair or table.&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; Generally&amp;nbsp;speaking a&amp;nbsp;child type (here type refers to class) may belong to more than one base type(this is called as multiple inheritance) but in most of the modern languages this is avoided due to higher complexity in multiple inheritance.&lt;BR&gt;&amp;nbsp;&amp;nbsp;in almost all cases a&amp;nbsp;type can be&amp;nbsp;calssified as inheriting from one main base type.&amp;nbsp;Like a human(child) is an animal(base) and a cat(child) is also an&amp;nbsp;animal(base).&amp;nbsp;However types can also be classified according to thier behaviours like a human can move and a car can also move. However since most languages dont allow inheritance we define behaviours by implementing interfaces. in&amp;nbsp; addition implementing an interface will guarantee that a certain behaviour is present.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;for example i&amp;nbsp;have&amp;nbsp;different classes each that calculate&amp;nbsp;specific type of&amp;nbsp;bills&amp;nbsp;(like waterbill, electricitybill, telephonebill)&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;i have another function that calculates the&amp;nbsp; total of all bills. this function takes an array of objects&amp;nbsp;of bill types. It then calls calculate method&amp;nbsp; of each object and add the returned billvalue to calculate the total.&amp;nbsp;To ensure that all these objects have the method calculate&amp;nbsp;these inherit from the interface IBill and have to implement its method calculate. The code will help to shed more light on the&amp;nbsp;same&lt;BR&gt;&amp;nbsp;&amp;nbsp; public interface IBill{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int calculate();&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp; //other classes inherit from the interface&lt;BR&gt;&amp;nbsp; public class waterbill:IBill{&lt;BR&gt;&amp;nbsp;&amp;nbsp; public int calculate(){ //calculates bill and returns}&lt;BR&gt;}&lt;BR&gt;&amp;nbsp;public class electricitybill:IBill{&lt;BR&gt;&amp;nbsp;&amp;nbsp; public int calculate(){ //calculates bill and returns}&lt;BR&gt;}&lt;BR&gt;&amp;nbsp;public class telephonebill:IBill{&lt;BR&gt;&amp;nbsp;&amp;nbsp; public int calculate(){ //calculates bill and returns}&lt;BR&gt;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&lt;BR&gt;then&amp;nbsp;a class called expenses has a function calculateexpenses&lt;BR&gt;&lt;BR&gt;public class expenses{&lt;BR&gt;&amp;nbsp;&amp;nbsp; public void displayExpenses(IBill []obj)&lt;BR&gt;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int tot=0;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i=0;i&amp;lt;obj.length;i++){&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tot+= obj[i].calculate(); //this can be called as all objects implement the ibill interface&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//finally print the total &lt;BR&gt;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;BR&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;as you can see there is also no need to type cast and the presence of calculcate method is guaranteed.&lt;BR&gt;&lt;BR&gt;I hope this first blog of mine helps. This has been a topic of lot of debate. I will try to come up with more articles on the same&lt;BR&gt;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------&lt;BR&gt;&lt;BR&gt;[1] I wonder if we can create a web page in asp.net without inheriting from the System.Web.UI.Page class. I am sure we can though i cant remember it now&lt;BR&gt;[2] For syntax of declaring abstract functions and classes please refer to msdn&lt;BR&gt;[3] For more info on interfaces refer to the msdn&lt;BR&gt;&lt;BR&gt;&lt;STRONG&gt;Cheers&lt;BR&gt;Sohail Sayed&lt;/STRONG&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5640777" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/sohailsayed/archive/tags/abstract+classes/default.aspx">abstract classes</category><category domain="http://weblogs.asp.net/sohailsayed/archive/tags/inheritance/default.aspx">inheritance</category><category domain="http://weblogs.asp.net/sohailsayed/archive/tags/General+Software+Development/default.aspx">General Software Development</category><category domain="http://weblogs.asp.net/sohailsayed/archive/tags/asp.net/default.aspx">asp.net</category><category domain="http://weblogs.asp.net/sohailsayed/archive/tags/interfaces/default.aspx">interfaces</category></item></channel></rss>