You need an abstraction whenever you have a class that you do not want to implement with all its methods. Those classes that inherit it will be forced to implement all these methods, otherwise you would also need to declare subclasses as abstract.
In addition to this, you should know the interface, interface methods should not have a body, and it’s good that your class can implement as much as you need. Whereas you can only inherit one abstract class. Interfaces are like contracts. Whatever class executes them, they must provide a body for all their methods.
If you need an abstract or interface, or both really depend on your design and what you want to implement. Although it is good practice to force those classes that have common methods for implementing the same interface (if you know nothing about the body of each method) or abstract (if you know that the body is some kind, all or none of methods)
Another example might be when you have an abstraction or interface, if you add something to them, all subclasses or classes that implement them should follow these changes, which means it would be easier to get the changes.
See this , this, and this and the open / close principle .
Jack
source share