+ 1
Why do we use abstract classes if we have the Normal ones....??
Is there any difference in both....? If yes, please tell me
1 Antwort
+ 1
If you want to force people to make subclasses, define an abstract class.
Here is the reason documented at https://www.geeksforgeeks.org/abstract-classes-in-JUMP_LINK__&&__python__&&__JUMP_LINK/:
"By defining an abstract base class, you can define a common Application Program Interface(API) for a set of subclasses. This capability is especially useful in situations where a third-party is going to provide implementations, such as with plugins, but can also help you when working in a large team or with a large code-base where keeping all classes in your mind is difficult or not possible. "
Here is my explanation:
Object-oriented design is pretty artistic or subjective. An objective and unarguable reason doesn't always exist. The reason often comes down to there being no useful implementation for one of its methods being possible at your class's level of abstraction. Since you can't make a useful implementation for all methods, the class on its own becomes useless without a concrete subclass that fills in the gap using a more specific level of abstraction.
It is the same in most languages that support class definitions.