‎2005 Mar 18 9:36 AM
Hello,
Can anybody please explain me the difference with an example between <b><i>Narrow Casting</i></b> and <i><b>Widening</b></i> <i><b>Casting</b></i> in ABAP Objects.
Regards
Kalyan
‎2005 Mar 18 10:28 AM
Hi Aswani,
Have a look at this url
http://help.sap.com/saphelp_47x200/helpdata/en/c3/021959f06111d4b2eb0050dadfb92b/frameset.htm
Thanks
Lakshman
‎2005 Mar 18 11:10 AM
Hi Kalyan
In fact, the names imply everything. Let me illustrate a bit. This illustration will deal with one aspect which I think will be enough at least to understand the concept simply. Think of two instances (objects) of two classes one of which is inherited from the other, that is; one is a general class and the other is a specialized class of it.
<u>e.g.</u>
Class 1 --> land_vehicle
Class 2 --> truck
The class <b>land_vehicle</b> has following attributes:
max_speed
number_of_wheels
number_plate
...The class <b>truck</b> has following attributes:
max_speed [inherited]
number_of_wheels [inherited]
number_plate [inherited]
<i>load_capacity</i> [special to truck class]Now, assume you have instantiated these classes as
<b>"land_vehicle_obj"</b> and <b>"truck_obj"</b> respectively from these classes.
Between these two objects, you can assign one to the other and at this point casting occurs.
i. If you assign <i>truck_obj</i> to <i>land_vehicle_obj</i> you lose the special attribute <i>load_capacity</i> since you go from the specialized on to the general one. Thus, this is a <b>narrowing cast</b>.
i. If you assign <i>land_vehicle_obj</i> and <i>truck_obj</i> you do not lose any attribute, nevertheless you add a new one. Thus this is a <b>widening cast</b>.
Regards
*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>