Thursday, November 15, 2012

Polymorphism

Polymorphism :

A Method or function will show different behaviours when we pass different no of arguments or different type of arguements to a method.A method can have more forms.This concept is called Polymorhism.

Polymorphism is one of the fundamental concepts of OOP.

Polymorphism provides following features: 

  
1. It allows you to invoke methods of derived class through base class reference during runtime.
2. 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 / Static Polymorphism / Overloading
2.  Run time polymorphism / Dynamic 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.  Overloading a 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)
:





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.

Imporant :

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.








 






Monday, November 5, 2012

Difference Between XML and HTML

Differences Between HTML and XML

HTML is an abbreviation for HyperText Markup Language while XML stands for eXtensible Markup Language.The differences are as follows:-


1.HTML was designed to display data with focus on how data looks while XML was designed to be a software and hardware independent tool used to transport and store data, with focus on what data is.


2.HTML is a markup language itself while XML provides a framework for defining markup languages.


3.HTML is a presentation language while XML is neither a programming language nor a presentation language.


4.HTML is case insensitive while XML is case sensitive.


5.HTML is used for designing a web-page to be rendered on the client side while XML is used basically to transport data between the application and the database.


6.HTML has it own predefined tags while what makes XML flexible is that custom tags can be defined and the tags are invented by the author of the XML document.


7.HTML is not strict if the user does not use the closing tags but XML makes it mandatory for the user the close each tag that has been used.


8.HTML does not preserve white space while XML does.


9.HTML is about displaying data,hence static but XML is about carrying information,hence dynamic.


Thus,it can be said that HTML and XML are not competitors but rather complement to each other


and clearly serving altogether different purposes.