Interface vs abstract class vs concrete class

The following points make you clear when to use interface, abstract class and concrete class in your java code implementation for a requirement.
  1. When there is only requirement specification provided and there is no clarity on the implementation, then we need to go for an interface to get the high level view of the requirement. This is 100% abstraction. Example: Servlet
  2. When we know about the implementation partially, then we should go for abstract classes. Abstract classes in this level help the programmer to add the implementation in future. Example:Generic Servlet, HTTPServlet
  3. If we know the implementation completely and ready to provide the service with the APIs, then we can go for concrete classes. Example: MyOwnServlet.
At the end of the requirement, we only need concrete classes to expose the API and to provide the services. The Interfaces and the Abstract Classes are used to develop the concrete classes.

No comments:

Post a Comment