Abstract class can contain default implementation inside it. Interface cannot contain any implementation inside it. It only contains definitions.
Interface mark the behavior between unrelated classes while abstract class impose you to derive the behavior.
we can not make instance of abstract class as well interface.
When Use Interface and Abstract Class
use interface when something in design will change frequently.
Abstract classes are provide some default behavior.abstract class are excellent candidates inside of application frameworks.
Abstract class let you define some behavior,they forces their subclasses to provide others.
Abstract class can contains abstract methods,abstract properties as well other like normal classes.
Interface can contain only abstract methods and properties but we don’t want to put abstract or public method.it is by default.

According to business logic of publish method having some default behavior then use abstract classes,if there is no default behavior and every drive has its own implementation then use interface.
if i made content class as interface then its difficult to make a changes in base class because we need to implement changes in all drive classes like adding new method in content interface.
CAN DO and IS-A also define difference between abstract class and interface.for example,if we have another interface “ICopy” which having behavior of copy and every drive class implemented it then we can say that “Article” class can do also copy.
IS-A is for generalization or specialization, means class “Content” is generalized form of Article,Blogs,Review are a specialized form of content class.
Abstract class is faster than interface because interface requires extra-in direction
No comments:
Post a Comment