Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Diff between interface and Abstract class

Former Member
0 Kudos

Hi to all,

I am woking on OOP in ABAP .Could any one can tell the difference between interface and abstract class.

thanks in advance .

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Sagar,

Interface is an pure abstact class. All methods under this class are abstract.The class which implements this interface will provide a implementation to this method

If you have one of the method in your class is abstract then the class will be abstract. You can not create any instacne for abstract classes.

Thanks,

Vinay

4 REPLIES 4

Former Member
0 Kudos

Hi Sagar,

Interface is an pure abstact class. All methods under this class are abstract.The class which implements this interface will provide a implementation to this method

If you have one of the method in your class is abstract then the class will be abstract. You can not create any instacne for abstract classes.

Thanks,

Vinay

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Taken from help..........

<i>

Interfaces are independent structures that allow you to enhance the class-specific public points of contact by implementing them in classes. Different classes that implement the same interface can all be addressed in the same way. Interfaces are the basis for polymorphism in classes, because they allow a single interface method to behave differently in different classes. Interface references allow users to address different classes in the same manner.

</i>

<i>

... ABSTRACT

Effect

A class defined as ABSTRACT cannot be instantiated, that is, you cannot use CREATE OBJECT with reference to the class. Instead, you can only address the class using its static components or its subclasses. The major purpose of an abstract class is to serve as a template for subclasses.

If a class contains abstract methods, that is, method declarations with the ABSTRACT addition, the whole class must also be abstract (that is, have the ABSTRACT addition), since a class may not be instantiated if it has unimplemented methods. Equally, if a subclass does not implement all of the abstract methods of its superclasses, it must itself declare them abstract.

Example

CLASS C1 DEFINITION ABSTRACT.

...

ENDCLASS.

CLASS C2 DEFINITION INHERITING FROM C1.

...

ENDCLASS.

DATA CREF TYPE REF TO C1.

START-OF-SELECTION.

CREATE OBJECT CREF TYPE C2.

Class C1 cannot be instantiated. However, the reference in the reference variable cref, defined with reference to class C1 can point to instances of the subclasses of C1 if these can be instantiated.

</i>

Regards,

Rich Heilman

uwe_schieferstein
Active Contributor
0 Kudos

Hello Sagar

An abstract class can have methods containing "default" coding that is inherited to sub-classes. In contrast, methods of an interface never have any coding.

With an abstract class you can deliver a "sample" or "default" implementation of the methods. This is not possible using interfaces.

Regards

Uwe

0 Kudos

Hello Sagar,

like Uwe told one basic difference is that you may provide some methods with an abstract class but not with an interface. The unique feature of interfaces is that you may implement several ones while abstract classes are limited to one inheritance hierarchy.

Regards

Klaus