Abstract Class pattern and its use in Java

This tutorial will show you what is Abstract Class Pattern and when we consider this Abstract Class Pattern in our application design.

Usage
Useful for designing a framework for the consistent implementation of the functionality common to a set of related classes.

An abstract class consists of one or more abstract methods that are only declared but contains no implementations that indicate variable parts of the class functionality. An abstract class may contain non-abstract methods that indicate non-variable parts of the class functionality. Later different classes are designed when abstract methods outlined in an abstract class need to be implemented to provide different functionality. An abstract class may not be directly instantiated. Hence when a class is designed as a non-abstract subclass of an abstract class, it must implement all abstract methods a parent abstract class contains. It is mandatory for a concrete subclass of an abstract class to implement all of its abstract methods in a consistent manner in terms of the method signatures. The implemented methods in the parent abstract class are automatically inherited by all subclasses. Thus it eliminates the redundant coding in all subclasses. The below figure shows an abstract class with three subclasses. Continue reading “Abstract Class pattern and its use in Java”