01-03-2007 1:50 PM
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 .
01-03-2007 1:58 PM
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
01-03-2007 1:58 PM
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
01-03-2007 2:00 PM
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
01-03-2007 2:00 PM
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
01-04-2007 5:14 PM
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