Abstract Classes: Classes which cannot be instantiated. This means one cannot make a object of this class or in other way cannot create object by saying ClassAbs abs = new ClassAbs(); where ClassAbs is abstract class.
Abstarct classes contains have one or more abstarct methods, ie method body only no implementation.
Interfaces: These are same as abstract classes only difference is we an only define method defination and no implementation.
When to use wot depends on various reasons. One being design choice.
One reason for using abstarct classes is we can code common functionality and force our developer to use it. I can have a complete class but I can still mark the class as abstract. Developing by interface helps in object based communication.
abstract classes are designed with implemantion gaps for sub-class to fill in.
interfaces are sintacticlly similar to classes but they lack insance variables & methods.
abstract classes can also have both abstract methods & non-abstract methods. where as in interface methods are abstract only, & variables are implicitly static&final.
 when u want to get the sub class(type) property into the super class(type),that we have to achive by using abstact class ,interface is one design we can se.
When we do not want any one to create object of our class we define the class as abstract. when we have some properties to which the functionalities that defer depending on the user specifications we use interfaces where the common properties are declared but the implementation is done by the user according to his will.
Abstract classes can perform the same operations as interfaces. But if we want to make a compulsory implementation of the functions, we have to use abstract class.
Also, use interfaces when you want to allow the user to inherit another class and use this as a sub-type.
We will use abstract class when we want that the parent class must implement some default behavoiur and keep some behavoiur to be imlemented by parent Class
Interface provides method signature and not the body. Its up to the developers to provide body for these methods once they implement it.
Abstract provides both, methods with and without body. Adding new methods in abstract class in middle of development life cycle won't break existing sub classes unless these methods are declared as mustoverride. If there are frequent addition of new methods, properties and so on., one should use abstract..
Adding new methods to the interface will force users to go through each and every sub class that implemented that interface and call these methods. So its always preferred to use abstract over interface because of this limitation.
Whereas on the other hand interface can fill gap of multiple inheritance. One can implement from more than one interface. Not same with Abstract. One can inherit from only one abstract class.
If you want to inherit from class that can provide reusable code then use abstract class. For instance, connecting to the database or base class for grid or treeview. If you implement your subclass from an interface then in each subclass you will have to write your own code to fill body of these methods.
When we do not want any one to create object of our class we define the class as abstract. when we have some properties to which the functionalities that defer depending on the user specifications we use interfaces where the common properties are declared but the implementation is done by the user according to his will."
That will still leave me wondering... When would someone not want to create object of some class? You also mentioned about when to define an interface.. But same is true for abstract class.. We can use abstract class to do exactly same thing that you stated for interface.. Plz correct me if I am wrong.
Interface: 1. If u want to implement all of the methods than we go for interface. 2. In future to put any methods that dows not effect. 3. To implemnting Inheritence Future
Abstarct:
1. when it necessay dont create the instance of the class for the security purpose.
1. If u want to implement all of the methods than we go for interface. 2. In future to put any methods that dows not effect. 3. To implemnting Inheritence Future
Abstarct:
1. when it necessay dont create the instance of the class for the security purpose. "
Underneath Interface:
Point 1. Right
Point 2. I believe this is not truly accurate.. Not trying to be instigator!!
If you want to put any methods that does not affect(I believe you meant that does not affect other class) then I would use abstract class not interface. Here's an explanation why? For instance, if you are already implementing from an interface in 10 different sub classes and if you add another method to the interface then you will have to go through each and every sub class and declare this method. Else you will get an error. So I believe point 2 should be under Abstract. Thats why I always prefer abstract over interface. Interface is bit more strict on implementation than abstract on inheritance.
Point 3. Interface supports multiple inheritance but C# does not truly support multiple inheritance like C++ and so one can use interface and can also implement from more than 1 interface.