<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Widening Casting / Down Casting in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/widening-casting-down-casting/m-p/11095160#M1902824</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rini,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Thanks for the quick reply. I understood the concept theoretically. but the problem I am having is implementing it practically in a program. I am also slightly confused in understanding if Interfaces are mandatory to have the widening casting implemented.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One more thing, I read somewhere that the casting operator "?=" is only used for widening casting ( Assigning the instance of a superclass to the sub-class ). However in the above explanation of yours I can see you have used the casting operator under the header "Narrow Casting" .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Santosh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 09 Jun 2015 17:49:33 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2015-06-09T17:49:33Z</dc:date>
    <item>
      <title>Widening Casting / Down Casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/widening-casting-down-casting/m-p/11095158#M1902822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I am learning ABAP OO and not able to catch the concept of widening casting. I also followed the below links, but still not able to understand. Kindly help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;is it mandatory to use interfaces when going for the widening casting(as I saw a couple of examples of widenin casting and everywhere they used the interface )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A __default_attr="92440" __jive_macro_name="blogpost" class="jive_macro jive_macro_blogpost" data-orig-content="Understanding Widening Cast in ABAP Objects" href="https://community.sap.com/" modifiedtitle="true" title="Understanding Widening Cast in ABAP Objects"&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jun 2015 16:59:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/widening-casting-down-casting/m-p/11095158#M1902822</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-06-09T16:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: Widening Casting / Down Casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/widening-casting-down-casting/m-p/11095159#M1902823</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Santosh ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Wide Casting : When you move the child class object reference to parent class object reference&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Narrow/Down Casting : Opposite i.e. parent class object ref to child class obj ref&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g.&amp;nbsp; Lets Say&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Parent class : Car&amp;nbsp; , Object ref : OBJ_CAR&lt;/P&gt;&lt;P&gt;Child Class : Sedan ( inherits Parent class Car) , object ref : OBJ_SEDAN&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Wide casting :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;obj_car = obj_sedan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Narrow/Down Casting :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;obj_sedan ?= obj_car&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Advantage of narrow casting is you can use the methods of the subclass and also that of parent class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it helps you to understand .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Rini&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;P.S : Pls mark the answer as correct/helpful if so.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jun 2015 17:28:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/widening-casting-down-casting/m-p/11095159#M1902823</guid>
      <dc:creator>former_member188458</dc:creator>
      <dc:date>2015-06-09T17:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Widening Casting / Down Casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/widening-casting-down-casting/m-p/11095160#M1902824</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rini,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Thanks for the quick reply. I understood the concept theoretically. but the problem I am having is implementing it practically in a program. I am also slightly confused in understanding if Interfaces are mandatory to have the widening casting implemented.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One more thing, I read somewhere that the casting operator "?=" is only used for widening casting ( Assigning the instance of a superclass to the sub-class ). However in the above explanation of yours I can see you have used the casting operator under the header "Narrow Casting" .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Santosh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jun 2015 17:49:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/widening-casting-down-casting/m-p/11095160#M1902824</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-06-09T17:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: Widening Casting / Down Casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/widening-casting-down-casting/m-p/11095161#M1902825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Santosh,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I just realized I mixed up the terminology ,my bad ( probably late night effect &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; ) . &lt;/P&gt;&lt;P&gt;It is the vice-a-versa . Here is the corrected one&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;Wide Casting : When you move the child class object reference to parent class object reference&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;Narrow/Down Casting : Opposite i.e. child class object ref to parent class obj ref&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;e.g.&amp;nbsp; Lets Say&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;Parent class : Car&amp;nbsp; , Object ref : OBJ_CAR&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;Methods : get_mileage&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;Child Class : Sedan ( inherits Parent class Car) , object ref : OBJ_SEDAN&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt; &lt;SPAN style="color: #333333; font-size: 12px;"&gt;Methods : get_mileage (inherited from parent but redefined)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get_back_space ( new method of child class)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;Wide casting :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;obj_sedan ?= obj_car&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;So when u do wide casting you can access parent class methods as well as methods belonging to child class e.g. in above case &lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt; you can access&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt; OBJ_SEDAN-&amp;gt;&lt;/SPAN&gt;get_back_space&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;Narrow/Down Casting :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;obj_car = obj_sedan&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;When you do Narrow casting&amp;nbsp; you can only access the methods belonging to parent class however if the method is re-defined in the child class , the parent class object reference calls the child class method implementation . &lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;e.g. in above scenrio u cannot call &lt;SPAN style="color: #333333; font-size: 12px;"&gt;get_back_space method using the obj_car ref , but u can call &lt;SPAN style="color: #333333; font-size: 12px;"&gt;get_mileage method and because it is re-defined in the child class so it will call the child class implementation of method &lt;SPAN style="color: #333333; font-size: 12px;"&gt;get_mileage .&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt; OBJ_SEDAN-&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;get_mileage&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;Regarding your question related to Interface : Implementing Interface in classes is another kind of polymorphism(providing multiple forms)&amp;nbsp; , which you can think as simlar to inheritance i.e.&amp;nbsp; parent class &amp;amp; child class relation .&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;class . Only difference is Interface methods have no implementation but the implementing class has the implementation. &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;e.g. if we take the above case again , lets say&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;Interface : IF_CAR &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt; methods : get_mileage&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;Class which Implements IF_IAR : CL_SEDAN &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt; methods : get_milage ( with method code / implementation)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #333333; font-size: 12px;"&gt; get_back_space ( new method of child class)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;and you have the same narrow and wide casting beahivor as explained above .&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;Hope it helps you to understand better.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;Rini&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Jun 2015 04:22:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/widening-casting-down-casting/m-p/11095161#M1902825</guid>
      <dc:creator>former_member188458</dc:creator>
      <dc:date>2015-06-10T04:22:49Z</dc:date>
    </item>
  </channel>
</rss>

