2

I am still confused when abstract class doesn't contain any abstract method, what a purpose of it? why don't use regular class rather than abstract class if it doesn't contain any abstract method ? In fact, I was saw this situation is applied on java and libgdx library or perhaps for every library. So, because this situation, I was thinking is it very important to know why use abstract class without abstract method rather than regular class.

Okem
  • 395
  • 1
  • 4
  • 12

2 Answers2

1

When you make a class abstract (either with or without abstract methods), you are forcing the users of this class to create concrete sub-classes of it, since they can't instantiate it.

Eran
  • 387,369
  • 54
  • 702
  • 768
  • 1
    This is obvious. The question is: why would you want to do that? Your `abstract class` already implements all methods. Of course, the user may overwrite them when extending the `abstract class`, but why deny her/him the instantiation of your `abstract class`? Can you think of a good use case for this? – Turing85 Jul 20 '15 at 08:52
  • Scalability, in a nutshell. – Bathsheba Jul 20 '15 at 08:56
  • @Bathsheba was this comment a response to mine? If so, would you mind to elaborate? – Turing85 Jul 20 '15 at 08:58
  • 1
    The only possible answer can be " The base class has something to offer to all it's children". The derived classes are free to have their own implementations but the base implementation would still serve "some" purpose. – Geek Jul 20 '15 at 09:04
1

A user of an abstract class must create a concrete derived class.

This can be useful since it allows the author of an abstract class to introduce abstract functions at a later date. The amount of refactoring necessary at that time is then significantly reduced.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483