Abstract Class

Abstract Classes are mostly used in one of two ways -

Both these ways are better off substituted and hence an abstract class should almost never be used since you should try to prefer Composition over Inheritance.

However, this is still a principle and a principle is just in principle.

Some other scenarios where Abstract class may be used:

  • The classes you extend require methods with access modifiers other than public.
  • You want to declare non-static or non-final fields. This allows you to define methods that can access and modify the state of the object to which they belong.

You can still consider the above scenarios or use Abstract Class as Stepping Stone.

References


Children
  1. Abstract Class as Stepping Stone
  2. Abstract Class as a Helper Class
  3. Abstract Class for Providing Flexible Behavior for Related Classes