Difference Between Abstract Class and Interface

by | Jun 11, 2019 | ABAP Differences

Home » SAP » ABAP » ABAP Differences » Difference Between Abstract Class and Interface

Preface – This post is part of the Differences in ABAP for Interviews series.

Before jumping to the Difference between Abstract Class and Interface, let us have a short introduction of the two.

Introduction

Classes, their instances/objects, and access to objects using reference variables forms the basics of ABAP Objects.  A class represents a set of properties or methods that are common to all the objects of one type. However, it is necessary for similar classes to have similar functions that behave differently in each class and having a uniform point of contact.

ABAP objects make it possible by using Interface and abstract class.

Like Classes, interface acts as a data type for the objects. The components of interface are the same as of classes. Interface is used when similar classes have same method with the same name but different functionalities. Interface along with inheritance provides a base for polymorphism because methods of the interface can behave differently in different classes.

Abstract class is a class that contains one or more abstract methods i.e. methods without implementation. This class cannot be instantiated, as the abstract methods have to be implemented in a subclass of the inheritance tree. It can inherit only one class and multiple interfaces. You can explore more about Abstract class in SAP ABAP here.

Now, let us have a look at their difference.

Difference between Abstract Class and Interface

InterfaceAbstract Class
It is not a class. It is an independent structure that is used in a class to extend the functionality of a class.It is a special class which can’t be instantiated.
It is an entity that doesn’t have an implementation.It can contain methods with implementation as well as without implementation.
No common behaviour is implemented via Interface.For non-abstract methods, common behaviour can be implemented.
It can inherit multiple interfaces but cannot inherit a class.It can inherit a class and multiple interfaces.
Multiple inheritance can be achieved.There is only one abstract class as Super Class.
For new methods, all the implementing classes must implement the new methods.For new non-abstract methods, there is no need to redefine the method.
All components are PUBLIC by default.The visibility of each component can be set.

 

Author

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Author