Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3019

Doubts regarding abstract classes and interfaces

$
0
0

Hi Learners,

 

I need a clarification on the following topics please help.

 

 

1. I know how interface works and its purpose , I would like to know a real time example if someone implemented this in a particular situation.

 

2.Assume I have implemented an interface IF1 in a class CL_IMP1, Here I can directly access the functionality of CL_IMP1 by using its objects

 

           by the following method

          

    (a)          DATA : cl_ref type ref to CL_IMPL1.

               create object cl_ref.

               call method cl_ref->IF1~method( ).

 

But why would some one go , by creating a ref to Interface and assigning to class object.

 

    (b)           DATA : if_ref type ref to IF1.

               DATA : cl_ref type ref to CL_IMP1.

                create object cl_ref.

                if_ref = cl_ref.                                        "Upcasting

 

               call method if_ref->method().         

 

What makes the difference between (a) and (b)

 

3. And also which is the best situation to use an abstract class, I'm getting confused when the Interface and Abstract should be used.

 

 

A real time scenario would clarify my doubts more clearly, please help.

 

 

Regards,

Nagendra


Viewing all articles
Browse latest Browse all 3019

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>