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: 

ABAP Objects.. Abastract & Interface Class

Former Member
0 Kudos

What are the differences between Abstrac & Interface Class.. & In which condition we use abstract class and interace in Abap Objects?

7 REPLIES 7

Former Member
0 Kudos

Abstract Classes are provided as incomplete blueprint for complete subclasses.

Classes with atleast one abstract method are themselves abstract.

Interfaces are provided additional and independent of classes. They just describe which services are needed for a task to be carried out, but do not provide an implementation of the same.

It is similar (but not same) as an abstract class that only contains abstract methods.

Similarities between Interface and Abstract classes.

1. Both CANNOT be instantiated.

2. Can have references to both of them, which can hold objects of subclasses.

Differences.

1. Abstract classes contain one or more abstract methods - abstract methods are those which cannot have an implementation in the class itself.

2. Interfaces have all their methods abstract - none of them can have an implementation.

3. No visibility sections (PUBLIC, PRIVATE, PROTECTED) can be defined for interfaces, but can be defined for abstract classes.

0 Kudos

Hi Versha,

Thanx for Reply.

I know all these points, but I want to know In which condition we go for Abstarct & Interface, & which one is good performance wise that i want.

Thanks & Regards.

Ranveer

0 Kudos

Hi Ranveer,

Performance wise, I would advise you to go for interfaces.

Interfaces are more generic than abstract classes. So, they have a wider acceptance and wider applicability.

If you do not know the nature of subclasses that will require inheritance, go for interfaces.

By coding abstract classes, you would be restricting atleast some if not all your development for further use of your subclasses. You would require to be very clear about certain functionalities of the abstract class and subclasses when you design abstract classes.

Unless you have a very specific design reason to do so, do not go for abstract classes.

Regards,

Varsha

Former Member
0 Kudos

hi ranveer,

You cannot instantiate objects in an abstract class. This does not, however, mean that references to such

classes are meaningless. On the contrary, they are very useful, since they can (and must) refer to

instances in subclasses of the abstract class during runtime. The CREATE-OBJECT statement is extended

in this context. You can enter the class of the instance to be created explicitly:

CREATE OBJECT <RefToAbstractClass> TYPE <NonAbstractSubclassName>.

Abstract classes are normally used as an incomplete blueprint for concrete (that is, non-abstract)

subclasses, in order to define a uniform interface, for example.

Abstract instance methods are used to specify particular interfaces for subclasses, without having to

immediately provide implementation for them. Abstract methods need to be redefined and thereby

implemented in the subclass (here you also need to include the corresponding redefinition statement in the

DEFINITION part of the subclass).

Classes with at least one abstract method are themselves abstract

Static methods and constructors cannot be abstract (they cannot be redefined).

Interface only has a declaration

An interface corresponds to an abstract class that

only contains abstract methods

Interfaces are implemented in classes

Interfaces do not have visibility sections

Hope this is helpful, Do reward.

0 Kudos

Hi Runal,

Thanx for Reply.

Can we use abstract class with interface... if yes then in which condition & can we redefine or inherit abstarct class or interface class and when?

With Best Regards

Ranveer Singh

ranveerpsingh@gmail.com

Former Member
0 Kudos

Hi,

Abstract class is a class which contain one or more abstract methods, which has to be implemented by sub classes. Inteface is a Java Object containing method declaration and doesn't contain implementation. The classes which have implementing the Interfaces must provide the method defination for all the methods.2. Abstract class is a Class prefix wtih a abstract keyword followed by Class definaton. Interacace is a Interface which starts with interface keyword.3. Abstract class contatins one or more abstract methods. where as Interface contains all abstract methods and final declarations.4. Abstract class contains the method defination of the some methods. but Interface contains only method declaration, no defination provided.5. Abstract classes are useful in a situation that Some general methods should be implemented and specialization behaviour should be implemented by child classes. Interafaces are useful in a situation that all properties should be implemented we can use this scenario.

the main differences between an interface class and abstract class are

1.abstract classes must be given by keyword abstract,where as in interface class with key word interface

2.every method in interface class should be abstract,but this is not necessary in abstract class

3.by default what ever variables we decalre in interface are public static final,where as in abstract class they can be default and instance variables also

regards,

vasavi.

kindly reward if helpful.

Former Member
0 Kudos

Hi

Abstraction is used to manage complexity

Focus on the essential characteristics

Eliminate the details

Find commonalities among objects

Defines the public contract

Public definition for users of the object

The “Outside view”

Independent of implementation

Interfaces are independent structures that you can implement in a class to extend the scope of that class.

a universal point of contact.

They provide one of the pillars of polymorphism, since they allow a single method within an interface to behave differently in different classes.

Global & Local Interfaces

The definition of a local interface <intf> is enclosed in the statements:

INTERFACE <intf>.

...

ENDINTERFACE.

The definition contains the declaration for all components (attributes, methods, events) of the interface.

They automatically belong to the public section of the class in which the interface is implemented.