Abstract Class
Abstract Classes are mostly used in one of two ways -
- Abstract Class for Providing Flexible Behavior for Related Classes: If classes you extend have many common methods and fields, we tend.
- Abstract Class as a Helper Class: You want to share code among several closely related classes
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
-
If we are designing small, concise bits of functionality, use interfaces. If we are designing large functional units, use an abstract class.
Children