|
ABAP Tutorials -
Object Oriented ABAP
|
|
Written by Varun Verma
|
|
Tuesday, 09 September 2008 17:42 |
|
Abstract Classes: A class that is defined as ABSTRACT cannot be instantiated. This means that you cannot use CREATE OBJECT with reference to the class. If a class contains any abstract method then the whole class becomes abstract. A method, which is abstract, should be redefined in derived class. An Abstract class can declare and implement non abstract methods which its subclasses can use with or without redefining them. The use of abstraction through abstract classes is restricted to the sub classes of a specific node within the inheritance tree. The syntax to define a method as abstract method is shown below. Note if you are working with global classes then in the SE24 transaction you can define a class as abstract class in the properties tab.

Why use a abstract class? An abstract class is used when we want to model an object, the final state of which is not known at the time of modelling and will be known later. Final Class: A class that is defined as final class can not be inherited further. All Methods of a final class are inherently final and must not be declared as final in the class definition. Also, a final method can not be redefined further. If only a method of a class is final then that class can be inherited but that method cannot be redefined.
Syntax for final class: CLASS final_class DEFINITION FINAL. METHODS final_method FINAL. ENDCLASS.
Why use a final class? If you don't want anyone else to change or override the functionality of your class then you can define it as final. Thus no one can inherit and modify the features of this class.
|