12-21-2010 2:11 PM
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.
12-21-2010 2:36 PM
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.
12-21-2010 2:44 PM
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
12-21-2010 3:49 PM
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
12-23-2010 6:53 AM
Hi,
Abstract class generally used to design prototype of a system. So system can be simpler in terms of development.
Regards,
Pradip Patel