Wednesday, August 20, 2014

Difference between Abstract Class and Interface

1. An abstract class can have abstract members as well non abstract members. Whereas in an interface all the members are implicitly abstract.

2. A class can inherit one or more interfaces, but only one abstract class. So, with the help of Interface C# support multiple inheritance.

3. Abstract class is refererence type because it's a class. In an Interface we can't say anything until then, who is going to be implement. If a class is implement it behaves like a reference type and if a structure implement, then it behaves like value type.
e.g.  

    interface MyName                                                     
     {
         void Name();
     }

    struct StructInterface:MyName                                       public class clsInterface : MyName
    {                                                                                      {
         public void Name()                                                          public void Name()
         {                                                                                         {
             Console.Write("My Name");                                               Console.WriteLine("My Name");
         }                                                                                         }
    }                                                                                       }

4. Abstract class provide partial abstraction while Interface provide full abstraction.

5. Generally, abstract class used where, we have partially idea about the thing, that somewhere we confirm over the logic and somewhere not. But in the case of Interface we don't have any idea related the thing.





Monday, August 18, 2014

Difference between bug, error and exception

"One of the most confusing question I would say".
I have a story to simplify these three concepts:
Suppose I planned to go from India to London. Took my flight from New Delhi Airport for London. I kept in my mind the time when the flight will land in London. But when I woke-up, I was in Dubai. This is called Bug. Irrelevant result. Everything looks fine but the output is not as expected. 

Second one is ERROR: When I reached the airport to take my flight, there was some problem in the Air-Bus due to which the flight got delayed. This problem is called error and without fixing it, we are not able to execute the code. We have to fix it first.

And the last one is EXCEPTION. Let's suppose when I'm in the flight, and mid-way, all the engine of the plane stopped working due to unexpected reasons but I landed safely. Common belief would be that the plane is going to be crashed but this did not happen and all the passengers are safe. This is called EXCEPTION.  I'm still alive and running.

Same thing happens in a Program also. You don't come to know that some circumstances are generated in your program and by these circumstances, you believed that the program will surely crash/Stop but it did not happen. Because these exceptions are handled in our code.

For e.g. suppose a SQL Connection Exception Occurred and you don't know  when your database is  going to crash. By these exceptions,your program will definitely crash and a Big Yellow page will come at user's end. To manage this, we need to handle these exception in our program to run the program hassle free.

So we can say that: exception handling features provide a way to deal with any unexpected or exceptional situations that arise while a program is running.