I have to explain to some students the use of abstract classes and interfaces, as I have a very tecnical background, I would like to know if you would help me to define an easy explanation for junior.Simple definition:What are the purposes of abstract classes, interfaces, and what is the difference between the two ?When is it appropriate to use one instead of the other?Thanks.
In simple words what are are the purposes of abstract classes and/or interfaces?
c#;object oriented
I'll see if I can do this with generic terminology without too much hand-waving.An interface is like a contract. It says that a class which implements the interface agrees to implement all of the functions declared (as signatures only; no function definition) by that interface. The class may do so in any way it chooses, and provide any other functionality, as long as it implements each one of the declared functions. An interface is useful when you want to be able to use some common functionality of otherwise unrelated classes- they share no implementation details, only the function signatures. In C#, function declarations within an interface are implicitly pure virtual.An abstract class is a partially defined class that cannot be instantiated. It (usually) includes some implementation, but leaves some functions as pure virtual- declared only by their signature. Pure virtual functions are not defined in the class that declares them, so they must be implemented by a subclass (unless it too is an abstract class). Only a subclass which defines all of the pure virtual functions can be instantiated. The purpose of an abstract class is to define some common behavior that can be inherited by multiple subclasses, without implementing the entire class. In C#, the abstract keyword designates both an abstract class and a pure virtual method.In practical terms, the difference between the two is that an interface defines only pure virtual functions, while an abstract class may also include concrete functions, members, or any other aspect of a class.