Last post Jun 17, 2015 12:41 AM by vahid bakkhi
Jun 15, 2015 02:39 AM|Mounika Nallagopu|LINK
When we declare class as a abstract, we can put all methods as abstract then
what is the difference between abstract class and interface in this case?
Jun 15, 2015 04:50 AM|PatriceSc|LINK
See https://msdn.microsoft.com/en-us/library/scsyfw1d(v=vs.71).aspx for differences between an abstract class and an interface.
Jun 15, 2015 11:13 PM|Weibo Zhang|LINK
Hi Mounika Nallagopu:
Abstract class is an abstraction of objects, can be understood as abstract classes as object class. Interface is a specification. Abstract classes mostly are a definition of in a series of closely related class. Interfaces are a convention of the common
features on some loose class. A class can implement more than one interface, but it can only extend one parent abstract class. An interface contains only methods, properties, indexers, events, but it cannot define fields and contains the methods implemented;
an abstract class can define a field, property, containing the implementing method. Interface can be used to value and reference types, abstract classes can only be applied to reference types. For example, a Struct can inherit interfaces and cannot inherit
There is a metaphor, aircraft can fly, birds can fly, they all inherit the same interface "Fly", but the F22 belonged to abstract class aircraft, pigeon belonged to an abstract class bird.
For more information, you could refer to the following article.
I hope it’s useful to you.
Jun 16, 2015 03:14 PM|JohnBert|LINK
Jun 16, 2015 04:20 PM|deadtroll|LINK
At its essence an abstract class defines structure and also can define some basic functionality while Interfaces only define structure with no implementation.
Interfaces are blueprints in that they only define the overall structure without concern as to how it actually accomplishes any of its methods. You can think of abstract classes as a base class in that it defines overall structure and default implementation.
Keep in mind derived classes can implement many interfaces while they can only inherit from one class.
Jun 17, 2015 12:41 AM|vahid bakkhi|LINK
A class may inherit several interfaces.
A class may inherit only one abstract class.
An interface cannot provide any code, just the signature.
An abstract class can provide complete, default code and/or just the details that have to be overridden.
Core VS Peripheral
Interfaces are used to define the peripheral abilities of a class. In other words both Human and Vehicle can inherit from a IMovable interface.
An abstract class defines the core identity of a class and there it is used for objects of the same type.
If various implementations only share method signatures then it is better to use Interfaces.
If various implementations are of the same kind and use common behaviour or status then abstract class is better to use.
Requires more time to find the actual method in the corresponding classes.
Adding functionality (Versioning)
If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method.
If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly.