What’s an abstract method?

Print anything with Printful



Methods are used in object-oriented programming to perform actions and manipulate data stored within an object. Abstract methods are placeholders for subclasses to complete implementation. Superclasses contain multiple subclasses with similar states and behaviors. Using abstract methods allows for subclassing idempotence and minimizes programming for each specific subclass.

In object-oriented programming, subroutines called “methods” are used to perform functions in a program. These methods consist of programming statements that perform an action, set input parameters to customize actions, and can return or return a value of some type of object or class. Methods are the actions performed in a program by a certain class or within an object and are used to access and manipulate data stored within an object. There are many different methods and each has a particular use. A specific type executed by an abstract superclass and inherited by subclasses is known as an abstract method.

Typically, the abstract method does little or no implementation within its abstract super class. The codes contained in this type of method are considered dummy code and are not implemented by themselves. This does not mean that the specific abstract method in a particular abstract class is not used. Rather, the abstract method serves as a template or placeholder for subclasses to complete the method implementation.

Super classes can contain multiple subclasses, and all subclasses of a super class have certain similar states and behaviors. Abstract classes, therefore, are a type of virtual class that exhibit virtual inheritance. This means that any subclass derived from a superclass inherits the restrictions of the superclass it derives from. Therefore, methods in subclasses are derived from abstract methods of superclasses. When programming and using abstract methods, the programmer must declare the class abstract instead of virtual.

For example, a “Graphic Objects” super class contains the subclasses “Circle”, “Square”, etc. Therefore, all circles and squares have the same states – orientation, position, fill color, line color – and behaviors – moveTo , scale, rotate, draw – as “Graphic Objects”. All subclasses of this super class have the same qualities, but are implemented in different ways. The abstract method of the super class provides the basics without implementation and the subclasses do the actual implementation using the same methods. Even though each subclass uses the same method as the abstract class, it uniquely defines how the method will be executed.

Using an abstract method allows generalization to the higher level, or superclass, and specification to lower levels, or subclasses. This hierarchy minimizes the amount of method programming for each specific subclass. Using these methods also allows for subclassing idempotence, which means that if a method is implemented over and over again, the result is the same every time.




Protect your devices with Threat Protection by NordVPN


Skip to content