21.03.2013 Views

Object Oriented ABAP

Object Oriented ABAP

Object Oriented ABAP

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Demo on "Narrow Casting"<br />

Definition: The assignment of a subclass instance to a reference variable of the type<br />

"reference to super class" is described as a narrowing cast, because you are switching from<br />

a more detailed view to a one with less detail. It is also called as up-casting.<br />

Use of narrowing casting:<br />

A user who is not interested in the finer points of cars, trucks, and busses (but only, for<br />

example, in the fuel consumption and tank gauge) does not need to know about them. This<br />

user only wants and needs to work with (references to) the lcl_vehicle(super class) class.<br />

However, in order to allow the user to work with cars, busses, or trucks, you generally need<br />

a narrowing cast.<br />

Principle of narrowing casting:<br />

1. In narrowing casting the object which is created with reference to the sub class is<br />

assigned to the reference of type super class.<br />

2. Using the super class reference it is possible to access the methods from the object<br />

which are only defined at the super class.<br />

3. This access is also called as generic access as super class is normally called as<br />

general class.<br />

Example:<br />

Super class: vehicle (contains general methods)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!