Wednesday, 24 September 2014

Object Oriented Programming Concepts (OOPS) in C#.net

OOPS


Class,Structure & Object
Encapsulation
Inheritance
Polymorphism
Abstraction
Interface
Generics
Enums

Class , Structure & ObjectMay 11, 2011Class:

  • Class is group of objects that share common properties and relationships.
  • Class members are private by default.
  • Classes are reference type that is they are stored on heap
  • Class can be inherited and but can be instantiated
Class Employee{public in CustID;public in CustName;} Structure:
  • Structure is collection of different types of data types.
  • Structure embers are public by default
  • Structure are value type that is they are stored on stack
  • Structure can not be inherited but can be instantiated
Struct Employee{public int CustID;public string name;} Object:
  • Object is basic runtime entity OR object is instance of class.
  • Object consistsof data and function together
  • Object allows designing systems that are more robust and portable through the proper application of abstraction
public class Student{ public string First_Name { get; set; } public int Weight { get; set; } public Person(string First_Name, int Weight) { First_Name = first_Name; Weight = weight; } //Other properties, methods, events...}class Program{ static void Main() { Student person1 = new Student("Anil", 66); Console.WriteLine("Student First_Name = {0} Weight = {1}", person1.First_Name, person1.Weight); }} Student First_Name = Anil Weight = 66
Encapsulation:
Encapsulation is a process of binding the data members and member functions into a single unit.
Example for encapsulation is class. A class can contain data structures and methods.
Consider the following class
public class Aperture
{
public Aperture ()
{
}
protected double height;
protected double width;
protected double thickness;
public double get volume()
{
Double volume=height * width * thickness;
if (volume<0)
return 0;
return volume;
}
}
In this example we encapsulate some data such as height, width, thickness and method Get Volume. Other methods or objects can interact with this object through methods that have public access modifier
Abstraction:
Abstraction is a process of hiding the implementation details and displaying the essential features.
Example1: A Laptop consists of many things such as processor, motherboard, RAM, keyboard, LCD screen, wireless antenna, web camera, usb ports, battery, speakers etc. To use it, you don't need to know how internally LCD screens, keyboard, web camera, battery, wireless antenna, speaker’s works.  You just need to know how to operate the laptop by switching it on. Think about if you would have to call to the engineer who knows all internal details of the laptop before operating it. This would have highly expensive as well as not easy to use everywhere by everyone.
So here the Laptop is an object that is designed to hide its complexity.
How to abstract: - By using Access Specifiers
.Net has five access Specifiers
Public -- Accessible outside the class through object reference.
Private -- Accessible inside the class only through member functions.
Protected -- Just like private but Accessible in derived classes also through member 
functions.
Internal -- Visible inside the assembly. Accessible through objects.
Protected Internal -- Visible inside the assembly through objects and in derived classes outside the assembly through member functions.
Let’s try to understand by a practical example:-
public class Class1
    {
        int  i;                                         //No Access specifier means private
        public  int j;                                        // Public
        protected int k;                             //Protected data
        internal int m;                        // Internal means visible inside assembly
        protected internal int n;                   //inside assembly as well as to derived classes outside assembly
        static int x;                                 // This is also private
        public static int y;                       //Static means shared across objects
        [DllImport("MyDll.dll")]
        public static extern int MyFoo();       //extern means declared in this assembly defined in some other assembly
        public void myFoo2()
        {
            //Within a class if you create an object of same class then you can access all data members through object reference even private data too
            Class1 obj = new Class1();
            obj.i =10;   //Error can’t access private data through object.But here it is accessible.:)
            obj.j =10;
            obj.k=10;
            obj.m=10;
            obj.n=10;
       //     obj.s =10;  //Errror Static data can be accessed by class names only
            Class1.x = 10;
         //   obj.y = 10; //Errror Static data can be accessed by class names only
            Class1.y = 10;
        }
    }
Now lets try to copy the same code inside Main method and try to compile
[STAThread]
        static void Main()
        {
           //Access specifiers comes into picture only when you create object of class outside the class
            Class1 obj = new Class1();
       //     obj.i =10; //Error can’t access private data through object.
            obj.j =10;
      //      obj.k=10;     //Error can’t access protected data through object.
            obj.m=10;
            obj.n=10;
       //     obj.s =10;  //Errror Static data can be accessed by class names only
            Class1.x = 10;  //Error can’t access private data outside class
         //   obj.y = 10; //Errror Static data can be accessed by class names only
            Class1.y = 10;
        }
What if Main is inside another assembly
[STAThread]
        static void Main()
        {
           //Access specifiers comes into picture only when you create object of class outside the class
            Class1 obj = new Class1();
       //     obj.i =10; //Error can’t access private data through object.
            obj.j =10;
      //      obj.k=10;     //Error can’t access protected data through object.
     //     obj.m=10; // Error can’t access internal data outside assembly
    //      obj.n=10; // Error can’t access internal data outside assembly
       //     obj.s =10;  //Errror Static data can be accessed by class names only
            Class1.x = 10;  //Error can’t access private data outside class
         //   obj.y = 10; //Errror Static data can be accessed by class names only
            Class1.y = 10;
        }
In object-oriented software, complexity is managed by using abstraction.
Abstraction is a process that involves identifying the critical behavior of an object and eliminating irrelevant and complex details.
Inheritance:
Inheritance is a process of deriving the new class from already existing class
C# is a complete object oriented programming language. Inheritance is one of the primary concepts of object-oriented programming. It allows you to reuse existing code. Through effective use of inheritance, you can save lot of time in your programming and also reduce errors, which in turn will increase the quality of work and productivity. A simple example to understand inheritance in C#.

Using System;
Public class BaseClass
{
    Public BaseClass ()
    {
        Console.WriteLine ("Base Class Constructor executed");
    }
                                 
    Public void Write ()
    {
        Console.WriteLine ("Write method in Base Class executed");
    }
}
                                 
Public class ChildClassBaseClass
{
                                 
    Public ChildClass ()
    {
        Console.WriteLine("Child Class Constructor executed");
    }
   
    Public static void Main ()
    {
        ChildClass CC = new ChildClass ();
        CC.Write ();
    }
}
In the Main () method in ChildClass we create an instance of childclass. Then we call the write () method. If you observe the ChildClass does not have a write() method in it. This write () method has been inherited from the parent BaseClass.
The output of the above program is 
Output:
  Base Class Constructor executed
  Child Class Constructor executed
  Write method in Base Class executed
this output proves that when we create an instance of a child class, the base class constructor will automatically be called before the child class constructor. So in general Base classes are automatically instantiated before derived classes.
In C# the syntax for specifying BaseClass and ChildClass relationship is shown below. The base class is specified by adding a colon, ":", after the derived class identifier and then specifying the base class name.
Syntax:  class ChildClassNameBaseClass
              {
                   //Body
              }
              {
                   //Body
              }
C# supports single class inheritance only. What this means is, your class can inherit from only one base class at a time. In the code snippet below, class C is trying to inherit from Class A and B at the same time. This is not allowed in C#. This will lead to a compile time 
error: Class 'C' cannot have multiple base classes: 'A' and 'B'.
public class A
{
}
public class B
{
}
public class C : A, B
{
}
In C# Multi-Level inheritance is possible. Code snippet below demonstrates mlti-level inheritance. Class B is derived from Class A. Class C is derived from Class B. So class C, will have access to all members present in both Class A and Class B. As a result of multi-level inheritance Class has access to A_Method(),B_Method() and C_Method(). 
Note: Classes can inherit from multiple interfaces at the same time. Interview Question: How can you implement multiple inheritance in C#? Ans : Using Interfaces. We will talk about interfaces in our later article.
Using System;
Public class A
{
    Public void A_Method ()
    {
        Console.WriteLine ("Class A Method Called");
    }
}
Public class BA
{
    Public void B_Method ()
    {
        Console.WriteLine ("Class A Method Called");
    }
}
Public class CB
{
    Public void C_Method ()
    {
        Console.WriteLine ("Class A Method Called");
    }
                   
    Public static void Main ()
    {
        C C1 = new ();
        C1.A_Method ();
        C1.B_Method ();
        C1.C_Method ();
    }
}
When you derive a class from a base class, the derived class will inherit all members of the base class except constructors. In the code snippet below class B will inherit both M1 and M2 from Class A, but you cannot access M2 because of the private access modifier. Class members declared with a private access modifier can be accessed only with in the class. We will talk about access modifiers in our later article. 
Common Interview Question: Are private class members inherited to the derived class?
Ans: Yes, the private members are also inherited in the derived class but we will not be able to access them. Trying to access a private base class member in the derived class will report a compile time error.
Using System;
Public class A
{
Public void M1 ()
{
}
Private void M2 ()
{
}
}
Public class BA
{
Public static void Main ()
{
B B1 = new B ();
B1.M1 ();
//Error, Cannot access private member M2
//B1.M2 ();
}
}
Method Hiding and Inheritance We will look at an example of how to hide a method in C#. The Parent class has a write () method which is available to the child class. In the child class I have created a new write () method. So, now if I create an instance of child class and call the write () method, the child class write () method will be called. The child class is hiding the base class write () method. This is called method hiding. 
If we want to call the parent class write () method, we would have to type cast the child object to Parent type and then call the write () method as shown in the code snippet below.

Using System;
Public class Parent
{
    Public void Write ()
    {
        Console.WriteLine ("Parent Class write method");
    }
}

Public class ChildParent
{
    Public new void Write ()
    {
        Console.WriteLine ("Child Class write method");
    }
   
    Public static void Main ()
    {
        Child C1 = new Child ();
        C1.Write ();
        //Type caste C1 to be of type Parent and call Write () method
        ((Parent) C1).Write ();
    }
}
Polymorphism:
When a message can be processed in different ways is called polymorphism. Polymorphism means many forms.

Polymorphism is one of the fundamental concepts of OOP.

Polymorphism provides following features: 
  • It allows you to invoke methods of derived class through base class reference during runtime.
  • It has the ability for classes to provide different implementations of methods that are called through the same name. 
Polymorphism is of two types:

  1. Compile time polymorphism/Overloading
  1. Runtime polymorphism/Overriding
Compile Time Polymorphism

Compile time polymorphism is method and operators overloading. It is also called early binding.

In method overloading method performs the different task at the different input parameters.

Runtime Time Polymorphism

Runtime time polymorphism is done using inheritance and virtual functions. Method overriding is called runtime polymorphism. It is also called late binding.

When overriding a method, you change the behavior of the method for the derived class.  Overloadinga method simply involves having another method with the same prototype.

Caution: Don't confused method overloading with method overriding, they are different, unrelated concepts. But they sound similar.

Method overloading has nothing to do with inheritance or virtual methods.

Following are examples of methods having different overloads:

void area(int side);
void area(int l, int b);
void area(float radius);

Practical example of Method Overloading (Compile Time Polymorphism)

using System;

namespace method_overloading
{
    class Program
    {
        public class Print
        {
           
            public void display(string name)
            {
                Console.WriteLine ("Your name is : " + name);
            }

            public void display(int age, float marks)
            {
                Console.WriteLine ("Your age is : " + age);
                Console.WriteLine ("Your marks are :" + marks);
            }
        }
       
        static void Main(string[] args)
        {

            Print obj = new Print ();
            obj.display ("George");
            obj.display (34, 76.50f);
            Console.ReadLine ();
        }
    }
Note: In the code if you observe display method is called two times. Display method will work according to the number of parameters and type of parameters.
When and why to use method overloading

Use method overloading in situation where you want a class to be able to do something, but there is more than one possibility for what information is supplied to the method that carries out the task.

You should consider overloading a method when you for some reason need a couple of methods that take different parameters, but conceptually do the same thing.

Method overloading showing many forms.

using System;

namespace method_overloading_polymorphism
{
    Class Program
    {
        Public class Shape
        {
            Public void Area (float r)
            {
                float a = (float)3.14 * r;
                // here we have used function overload with 1 parameter.
                Console.WriteLine ("Area of a circle: {0}",a);
            }

            Public void Area(float l, float b)
            {
                float x = (float)l* b;
                // here we have used function overload with 2 parameters.
                Console.WriteLine ("Area of a rectangle: {0}",x);

            }

            public void Area(float a, float b, float c)
            {
                float s = (float)(a*b*c)/2;
                // here we have used function overload with 3 parameters.
                Console.WriteLine ("Area of a circle: {0}", s);
            }
        }

        Static void Main (string[] args)
        {
            Shape ob = new Shape ();
            ob.Area(2.0f);
            ob.Area(20.0f,30.0f);
            ob.Area(2.0f,3.0f,4.0f);
            Console.ReadLine ();
        }
    }

Things to keep in mind while method overloading

If you use overload for method, there are couple of restrictions that the compiler imposes.

The rule is that overloads must be different in their signature, which means the name and the number and type of parameters.

There is no limit to how many overload of a method you can have. You simply declare them in a class, just as if they were different methods that happened to have the same name.
Method Overriding:

Base class method has to be marked with virtual keyword and we can override it in derived class usingoverride keyword.
Derived class method will completely overrides base class method i.e. when we refer base class object created by casting derived class object a method in derived class will be called.
Example: 
public class BaseClass
{
public virtual void Method1()
{
Console.Write("Base Class Method");
}
}
// Derived class
public class DerivedClass : BaseClass
{
public override void Method1()
{
Console.Write("Derived Class Method");
}
}
// Using base and derived class
public class Sample
{
public void TestMethod()
{
// calling the overriden method
DerivedClass objDC = new DerivedClass(); 
objDC.Method1();
 // calling the baesd class method
BaseClass objBC = (BaseClass)objDC; 
objDC.Method1();
}
}
Output
---------------------
Derived Class Method
Derived Class Method
Constructors and Destructors:
Classes have complicated internal structures, including data and functions, object initialization and cleanup for classes is much more complicated than it is for simple data structures. Constructors and destructors are special member functions of classes that are used to construct and destroy class objects. Construction may involve memory allocation and initialization for objects. Destruction may involve cleanup and deallocation of memory for objects.
  • Constructors and destructors do not have return types nor can they return values.
  • References and pointers cannot be used on constructors and destructors because their addresses cannot be taken.
  • Constructors cannot be declared with the keyword virtual.
  • Constructors and destructors cannot be declared const, or volatile.
  • Unions cannot contain class objects that have constructors or destructors.
Constructors and destructors obey the same access rules as member functions. For example, if you declare a constructor with protected access, only derived classes and friends can use it to create class objects.
The compiler automatically calls constructors when defining class objects and calls destructors when class objects go out of scope. A constructor does not allocate memory for the class object it’s this pointer refers to, but may allocate storage for more objects than its class object refers to. If memory allocation is required for objects, constructors can explicitly call the new operator. During cleanup, a destructor may release objects allocated by the corresponding constructor. To release objects, use the delete operator.
class C
{
       private int x;    
       private int y;
       public C (int i, int j)
       {
                 x = i;
                 y = j;
       }
       public void display ()     
       {
               Console.WriteLine(x + "i+" + y);
       }
}
Example of Destructor
class D
{
        public D ()
        {
            // constructor
        }         
        ~D ()
        {
           // Destructor
        }
}
Interface :
May 11, 2011
  • Interface is nothing but an contract of the system which can be implemented on accounts.
  • .Net doesn't support the multiple inheritance directly but using interfaces we can achieve multiple inheritance in .net.
  • An Interface can only contains abstract members and it is a reference type.
  • Interface members can be Methods, Properties, Events and Indexers. But the interfaces only contains declaration for its members.
  • Class which inherits interface needs to implement all it's methods.
  • All declared interface member are implicitly public.
class Program { interface BaseInterface { void BaseInterfaceMethod(); } interface DerivedInterface : BaseInterface { void DerivedToImplement(); } class InterfaceImplementer : DerivedInterface { public void DerivedToImplement() { Console.WriteLine("Method of Derived Interface called."); } public void BaseInterfaceMethod() { Console.WriteLine("Method of Base Interface called."); } } static void Main(string[] args) { InterfaceImplementer er = new InterfaceImplementer(); er.DerivedToImplement(); er.BaseInterfaceMethod(); Console.Read(); } } Method of Derived Interface called.
Method of Base Interface called.
Generics :
May 11, 2011
  • Generics allow us to have type or method which can operate on objects of various types, while providing type safety at the compile time.
  • That means if you define generics class object of type Integer & you are trying to add different type of variable to generic class like String then it will give compile time error.
  • In another sense, if we try to add different types in same list like string and int in a same list then compile time error will be thrown.
  • Generics are available under the namespace System.Collections.Generic.
  • The concept of type parameters is introduce to the .NET Framework with the help of Generics, which makes it possible to design classes & methods which defer the specification of one or more types until that class or method is declared and instantiated by the client code.
public class MyGenericClass { void Add(T val) { } } //Define a class which will consume MyGenericClass class MyGenericClass { static void Main() { // Declare a generic list having int as type MyGenericClass myGenericClassObj1 = new MyGenericClass(); // Declare a generic list of having string as type MyGenericClass myGenericClassObj2 = new MyGenericClass(); } } // Declare a generic list of having string as type MyGenericClass myGenericClassObj2 = new MyGenericClass(); } } } } Advantages:
  • Generics provide feature of Type Safety & it's performance is faster.
  • Generics can be used to create your own class of collection.
  • Using generic we can create your own generic methods, interfaces, classes, delegates and events.
Enums :
May 11, 2011
  • An enum is basically a value type with a set of related named constants often which is referred to as an enumerator list.
  • The enum keyword is for declaring an enumeration. An Enumeration is a primitive data type which is user defined data type.
  • An Enum is basically used to create numeric constants in .NET framework. All the member of an enum are ofenum type and there must be a numeric value for an each enum type.
  • Enums type can be integer (float, int, byte, double etc.). But if you used beside int it has to be cast.
  • Every enum type automatically derives from System.Enum and thus we can use System.Enum methods on enums.
class Program { public enum DayoftheWeek { Sunday = 1, Monday = 2, Tuesday = 3, Wednesday = 4, Thursday = 5, Friday = 6, Saturday = 7 } static void Main(string[] args) { string[] values = Enum.GetNames(typeof(DayofWeek)); int total = 0; foreach (string s in values) { Console.WriteLine(s); total++; } Console.WriteLine ("Total values in enum type is : {0}", total); Console.WriteLine (); int[] n = (int[])Enum.GetValues(typeof(DayofWeek)); foreach (int x in n) { Console.WriteLine(x); } Console.ReadLine(); } }
Output:
Whereas Overriding means changing the functionality of a method without changing the signature. We can override a function in base class by creating a similar function in derived class. This is done by usingvirtual/override keywords.
// Base class

Example of Constructor

Output:

Tuesday, 23 September 2014

Using Caching in ASP.NET Web Applications

Caching is a way which you can use to improve the performance of an ASP.NET Web applications. Caching is a location where you can store the data and access quickly. You have to use caching carefully and this post explains different caching mechanisms that available in ASP.NET web applications.The three ways that you can use to store the Cache data in ASP.NET applications are
Output Caching
Caching API
Using Cache in Data Source Controls
Output Caching
Output Caching allows you render the cached web page. When you request the web page very first time, the response will be added to the cache. Subsequent requests now onwards to the same page will be served from the cache. When you send the request second time, it actually would not process your code at server, it just returns the same HTML in the cache to the user. Enabling output cache is simple, add a OutputCache directive to your page directive as below
<%@ OutputCache Duration="60" VaryByParam="None" %>
The Duration is in seconds which tells the frequency that you want to cache the page before ASP.NET creates a new copy. This solution is ideal for static web pages where the content would not change very frequently. You can use VaryByParam for dynamic pages where the content changes by query string value. for example if your request page url looks as below
http://localhost:40967/Products/ViewDetails.aspx?Id=123
It caches the product id 123 details but when you pass another product id in query string then it fails to show that details as it is not in the cache. To overcome this issue, ASP.NET allows you to cache the specific version of the page. You can do this by setting VarByParam attribute in OutputCache.
<%@ OutputCache Duration="60" VaryByParam="Id" %>
You can not use OutputCaching when you have a user specific scenarios like theme personalisation, example when the page is requested and cached for first time logged in user theme will be placed in cache subsequent users when they sent request very first time they will see the theme that in the original request. Avoid using the OutputCaching when you want to show the user specific content on your page.
Caching API
Using the built-in Caching API, you can store and access the  items in cache through C# code. You can use Add or Insert methods to store items in Cache. The difference is Add method returns an object that represents the cached item where Insert method does not. If you add an item to Cache which is already present in cached it then fails where as in Insert method it replaces the existing item. The Add method can be used as below
 Cache.Add("DbConn", ConnectionString, new CacheDependency(filename),
    System.Web.Caching.Cache.NoAbsoluteExpiration,
    System.Web.Caching.Cache.NoSlidingExpiration, 
    System.Web.Caching.CacheItemPriority.Default,null);
You can define the CacheDependency item which can be used invalidate a cached item when the original source is changed. As soon as you changed the CacheDependency file, ASP.NET removes the item from the cache and puts it back by reading the original source file. The Cache Insert method looks as below
   Cache.Insert("DbConn", ConnectionString, new CacheDependency(filename));
You can set the time based expiration on Cached items using two ways
AbsoluteExpiration:Whether you use the cached item or not it will expire after specified amount of time. The data in the cached will expire whether you use the item or not. Use this expiration policy when there is a chance of less change in the cached data.
Cache.Add("DbConn", ConnectionString, new CacheDependency(filename),
    DateTime.Now.AddMinutes(1),
    System.Web.Caching.Cache.NoSlidingExpiration, 
    System.Web.Caching.CacheItemPriority.Default,null);
SlidingExpiration: In this expiration policy it expires the cached item after specific time if any request is not made during the specified time. Use this expiration policy when there is a chance of more change in the cached data.
Cache.Add("DbConn", ConnectionString, new CacheDependency(filename),
    System.Web.Caching.Cache.NoAbsoluteExpiration,
    TimeSpan.FromMinutes(1), 
    System.Web.Caching.CacheItemPriority.Default,null);
You can also notify the application when a particular item being removed from the Cache as shown below
Cache.Insert(
            "DbConn",
            ConnectionString,
            null,
            Cache.NoAbsoluteExpiration,
            new TimeSpan(0, 0, 15),
            CacheItemPriority.Default,
            new CacheItemRemovedCallback(ReportRemovedCallback));
   public static void ReportRemovedCallback(String key, object value,
    CacheItemRemovedReason removedReason)
        {
            // Write the logic here
        }
Using Caching in Data Source Controls
Caching is supported by all data source controls except SiteMap, LinqDataSource and EntityDataSource Controls. Data Source controls only cache database driven data. It would not cached the entire page. You can enable the caching for data source controls using EnableCaching attribute as shown below
<asp:SqlDataSource ID="SqlDataSource1" runat="server" CacheDuration="800"
     EnableCaching="True"> </asp:SqlDataSource>
Note: Items will be removed from the cache itself when Web Application or Web Server restarts.

Bootstrap for ASP.NET Development

It is critical for the web developers to target their websites to render on different devices and form factors. ASP.NET templates now using a framework called Bootstrap. What is Bootstrap? Bootstrap is front-end framework for easy and faster web development. This post explains how to use Bootstrap in  ASP.NET applications and outlines some of the features of this framework. Create a new ASP.NET project in Visual Studio 2013 and execute it then you will see the look and feel of the page as below.
image
If you want to get the above look without using Bootstrap then you have to write lot of custom CSS. Now all ASP.NET default templates like MVC, Web forms, Single Page applications and Web API are using Bootstrap framework. Bootstrap version 3 is integrated in Visual Studio 2013. The above screen scales well on different devices. If you look at the CSS code to achieve is very few lines as shown below
image
In order to get the Bootstrap into your project, go to Manage NuGet packages window and type Bootstrap in search box then you will find the package
image
once you install the package then it brings the following files into your project, All the CSS and JavaScript files related Bootstrap framework are bundled for you to get you better performance.
image
Another integration feature for Bootstrap is Bootswatch, which helps you to theme your site. To apply theme to your site go to Bootswatch site and choose the theme which you like and download and copy the CSS and overwrite the  Bootstrap.css in your project. After applying one of the sample free theme then the site looks as below, In matter of seconds you can quickly change the theme of your site.
image
Bootstrap works with grid layout. The above page is divided into 3 columns of width 4 each and it is very easy to change the layout of the page using CSS
image
if you want to change the layout of the page just change grid sizing something from value “col-md-4” to “col-md-6”. Make sure three columns added up to 12.
Another key feature of Bootstrap is dealing with the images, it makes the image experience as responsive without writing any code! just use the class name “img-responsive”.
image
It adds the responsive behaviour to the image and it make sure to render nicely in your site.
Another common requirement is styling the tables, If you use the class name table it will give you the outline to your table, you can add borders to table with class name table-bordered.
image
Bootstrap also has a nice feature called Glyph icons, for example if you want to add envelope to your support e-mail address then you can use class name glyphicon-envelope
image

Difference between 'classic' and 'integrated' pipeline mode in IIS7

Classic mode (the only mode in IIS6 and below) is a mode where IIS only works with ISAPI extensions and ISAPI filters directly. In fact, in this mode, ASP.NET is just an ISAPI extension (aspnet_isapi.dll) and an ISAPI filter (aspnet_filter.dll). IIS just treats ASP.NET as an external plugin implemented in ISAPI and works with it like a black box (and only when it's needs to give out the request to ASP.NET). In this mode, ASP.NET is not much different from PHP or other technologies for IIS.
Integrated mode, on the other hand, is a new mode in IIS7 where IIS pipeline is tightly integrated (i.e. is just the same) as ASP.NET request pipeline. ASP.NET can see every request it wants to and manipulate things along the way. ASP.NET is no longer treated as an external plugin. It's completely blended and integrated in IIS. In this mode, ASP.NET HttpModules basically have nearly as much power as an ISAPI filter would have had and ASP.NET HttpHandlers can have nearly equivalent capability as an ISAPI extension could have. In this mode, ASP.NET is basically a part of IIS.



Difference--2

Classic mode is where IIS only works with ISAPI extensions and ISAPI filters directly. This is how IIS 6 and below behaved. Using classic mode, ASP.NET is simply an ISAPI extension (aspnet_isapi.dll) and an ISAPI filter (aspnet_filter.dll). When using classic mode the server uses two piplines to handle requests, one for native code and the other for managed code. In this mode the application doesn't take full advantage of everything IIS 7.X has to offer.
Integrated mode handles all requests through a unified pipeline for IIS and is tightly integrated with ASP.NET through that same pipeline. ASP.NET sees every relevant request and manipulates things along the way rather than acting as an external plugin. With integrated mode ASP.NET runs much more efficiently in IIS and will yield greater performance for your site.