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: 

Purpose/Advantage of Abstract Class

Former Member
0 Kudos

Hi,

I'm aware of the functionality of the Abstract class.

But what is the purpose or advantage of using it. Where ever we are using an Abstract class, we can replace it with a normal class & achieve the same functionality. Is there any scenario like only Abstract class can be used?

Thanks & Regards,

Adithya M.

4 REPLIES 4

brad_bohn
Active Contributor
0 Kudos

Is there any scenario like only Abstract class can be used

No, but that's a general OOP conceptual question, not really a technical ABAP question. Study some of the many examples available anywhere OOP is discussed, not limited to SAP.

naimesh_patel
Active Contributor
0 Kudos

By using the Abstract class, we achieve the Polymorphism. Polymorphism simplifies the binding of the objects. By using the abstract class as the reference as object definition time, we can easily replace it with the concrete object at the runtime. This is called as the Dynamic Binding.

When we use the dynamic binding, the caller or the user of the object doesn't need to worry of what type of object is being passed to it at design time. At runtime the object would be assigned to it.

You can achieve the same Polymorphism and Dynamic binding using the interfaces, too. But the advantage using the Abstract class is, you could have the implementation of the non-abstract methods of the class where as Interface would only define the object. This non-abstract methods could contain the common logic which is valid for both Super class and Subclass.

Regards,

Naimesh Patel

MarcinPciak
Active Contributor
0 Kudos

Just adding to what Naimesh have said.

The downside of using abstract class in comparison to interfaces is that the class can inherit only one of the former, but implement lots the latter (at least in ABAP).

And as guys noticed, you are focusing on programming to an interface not an implementation , which makes the code higly flexible , not necessarly reusable .

Regards

Marcin

Former Member
0 Kudos

Hi,

Abstract class generally used to design prototype of a system. So system can be simpler in terms of development.

Regards,

Pradip Patel