Thursday, December 5, 2013

TAW12 - OBJECT ORIENTED REPOSITORY OBJECT

CREATING GLOBAL CLASSES IN THE OBJECT NAVIGATOR



Global classes can be created using the context menu in the navigation area of Object Navigator. In the Object Navigator screen, select the package or directly select the class node within the package and choose Create.
Subsequently, a dialog box appears where you need to specify additional attributes. You should not make any changes to the default attributes at this point.

DEFINITION OF ATTRIBUTES


When a class description is specified, the control automatically takes you to the Class Builder screen, as shown here. The Attributes tab helps you to list the required attributes of the class. You can also define new attributes here and use the input help to define the type of attributes.

DEFINITION OF METHODS


The Methods tab contains a list of all the method definitions in the class. You can add new methods and give a brief description of each of these by using the input help. It is crucial to specify the signature for each method. This can be done with the help of Parameter button.


DEFINITION OF METHOD SIGNATURES



When you select a method and click the Parameter button, a screen appears to specify the desired parameters for that method.
In this example, IV_NAME and IV_PLANETYPE are the defined parameters for the CONSTRUCTOR method.

IMPLEMENTATION OF THE METHODS



There are two ways of carrying out method implementation. You can either double-click a method name from the method list, or select a method and click the Source code button. Subsequently, the control shifts to the screen shown here. The source code implementation for the method is defined here. The Signature button on the screen displays the parameters of the method.

DISPLAYING THE METHOD DEFINITIONS



In the header area of the Class Builder screen, choose Goto  Method definition to modify the number of attributes of a method. You can define the handler method using the attributes tab.

DEFINITION OF COMPONENT USING THE NAVIGATION AREA 




You can define methods, attributes, and events in the Object Navigator’s context menu. You need to right-click the class name, and choose Create. After doing this, you can view the appropriate list of objects that can be created.

THE CLASS BUILDER TESTING ENVIRONMENT

To test an active global class, click the test icon in the initial Class Builder screen. An instance of the class needs to be created to test instance components. In the next screen, select the Instance button to create an instance of the class. You can execute the method by clicking the clock symbol, which appears as soon as the instance is generated.


SEPARATION OF NAVIGATION AND EDITING AREAS INTHE OBJECT NAVIGATOR


The navigation area and the editing area are two separate sections in the Object Navigator screen. You can view the Attributes and the Methods tabs in the navigation pane. You can use the ABAP Editor to make any changes in the objects in the navigation area.


OBJECT INSTANTIATION USING DRAG AND DROP

Drag a class name to the editing area by holding the left mouse button, in order to create an instance of the class in Object Navigator. The system automatically generates the CREATE OBJECT statement. You can then specify the reference variable and the parameters for the statement, if required.

METHOD CALLS USING DRAG AND DROP


You can generate method calls using drag and drop approach. For this, select a method name from the navigation area and drag it to the editing area. This automatically generates a CALL METHOD statement. However, you need to specify both the reference variable and the actual parameters.

DEFINING AN INHERITANCE RELATIONSHIP


You can define the inheritance relationship for a global class by choosing the Properties tab in the Class Builder screen. The system also proposes for a Superclass. In this example, ZCL_AIRPLANE_00, is the superclass, and its properties are inherited in the subclass.

REDEFINING AN INHERITED METHOD


An inherited method can be redefined using the redefine button. When a method is redefined, the Superclass call appears as a comment.

DEFINING GLOBAL INTERFACES


Global interface is created in Object Navigator in the same way as global class. Right-click the interfaces in the navigation area. In the resultant dialog box, you can specify the name of the Interface and give a description. You must adhere to the naming conventions meant for user-defined interfaces.

INCLUDING GLOBAL INTERFACES

Once an interface is defined, it automatically appears in the appropriate Method tab with the specified name. As shown here, double-click a method name to define the implementation f a global interface. However, interfaces can also be included in a class by selecting the Interfaces button.


IMPORTING A LOCAL PROGRAM CLASS



You need to follow a simple procedure to import local classes into a global class:
  Navigate to Class Builder using menu options or call transaction SE24.

  In the Initial Screen, select Object type → Import → Local classes in programs. Enter the Program name, and if local classes and interfaces exist within the program, select Expand Includes.

  Select Display Classes or Interfaces.

  Specify names for the global classes and interfaces that you want to create with the proper naming convention.

  Select the global classes and interfaces and click the Import button.

GENERATE A UML DIAGRAM FOR A PACKAGE



To view the UML diagram for your package, right-click the package name, select Display, and then select UML Class Diagram.

DEFINING A LOCAL TYPE



Local class or interface can be defined in a global class using Types. The components of the global class can access this local class or interface. However, they cannot be accessed from outside.

STRUCTURED DISPLAY OF INHERITED COMPONENTS



Click the Group by button to view the components of a global class in a structured format. Select the Group by interfaces and superclasses option to get the desired result.

SORTING THE COMPONENT DISPLAY OF GLOBAL CLASSES


The components can be sorted using the Sort button. You need to select the sorting criteria from the dialog box that appears. This shows the desired result.

SEPARATING THE NAVIGATION AND EDITING AREAS OF THE OBJECT NAVIGATOR


Global classes and interfaces are also included in the navigation area of the Object Navigator screen. Double-click an object name to edit it in the editing area.

OBJECT INSTANTIATION USING DRAG AND DROP



An instance of the class is created in Object Navigator. Drag the class name to the editing area. The system automatically generates the CREATE OBJECT statement. If required, the user specifies the reference variable and the parameters.

METHOD CALLS USING DRAG AND DROP

When you select a method name from the navigation area and drag it to the editing area, the CALL METHOD statement for that method is automatically generated. However, the reference variable and the actual parameters need to be specified.

WORKING WITH THE REFACTORING ASSISTANT


The existing repository objects can be modified using Refactoring Assistant. As shown in this example, Refactoring Assistant can be used to move the components of a class within the inheritance hierarchy.

____________________________________________________________________________

ABSTRACT  CLASSES AND ABSTRACT METHODS


You can use the keyword, ABSTRACT, to withhold a class from being instantiated. The syntax used for this is CLASS class_name DEFINITION ABSTRACT.
Methods of an abstract class can be of type abstract. This means that their implementation is not defined.

FINAL CLASSES AND METHODS.

The FINAL addition in a class definition prevents it from being inherited. The syntax followed is CLASS class_name DEFINITION FINAL. All the methods of a final class are by default final in nature, which means they cannot be redefined.

READ TO A TABLE WITH OBJECT REFERENCES

Object references that are similar in nature are stored in internal tables with key information. These references can be easily retrieved using this key information.

READ ACCESS USING PUBLIC ATTRIBUTES

When information is stored in an internal table with key values, the key attributes are specified as public with the READ ONLY addition to avoid redundancy. These public attributes can be directly accessed when internal tables are accessed. The keyword, TABLE_LINE, is used when the line type of an internal table is of elementary data type.

NAVIGATION METHODS AND CHAINING OF METHOD CALLS

Association implies that at runtime an instance of one class can store references to the objects of another class. In this example, lcl_vehicle and lcl_rental are the classes associated through the navigation method, get_vehicle. Initially, it was necessary to store the reference to the new object in a reference variable. Now, with the release SAP NetWeaver 7.0 EhP 2, we can chain method calls. Therefore, it is now possible to call a method of the object returned by the navigation method.

INSTANTIATION: VISIBILITY SECTIONS

The visibility of the instance constructor can be controlled, which means that the CREATE OBJECT statement used to instantiate this class is also restricted to specific areas.
  If the instance constructor is PRIVATE, then it can be instantiated only within the class.

  If the instance constructor is PROTECTED, then it can be instantiated by all the subclasses.

  If the instance constructor is PUBLIC, then it can be instantiated anywhere.



IMPLICIT SETTING OF THE INSTANCE CONSTRUCTOR'S VISIBILITY

The example shown in the slide gives a syntactical representation of the visibility concept. The visibility of the instance constructor is implicitly defined as PUBLIC, PRIVATE, and PROTECTED using the keyword, CREATE, in the class definition.


EXAMPLE FOR A CLASS WITH FACTORY METHOD

In this example, the class, lcl_airplane, keeps a reference of all its instances in a static attribute. The instantiation is permitted within the class itself and can only be done in static METHOD factory. When the method is called, it first checks if an identical instance already exists. If it does, then it returns the existing instance, instead of creating a new one.

SINGLETON CLASS 1: USING A FACTORY METHOD

Singleton class is a special case of the factory concept, wherein the class stores only one instance. The class is instantiated on the first call of the factory METHOD, get_instance. For all the future calls, only the reference of the existing object is returned.

SINGLETON CLASS 2 : USING THE STATIC CONSTRUCTOR

As shown in this slide, the class, lcl_singleton, makes use of a static constructor to create an instance. The get_instance method no longer creates an instance, but only returns the reference of an already existing one.

DEFINITION OF A FRIENDSHIP RELATIONSHIP BETWEEN CLASSES
A class can access the protected and private components of another class using the friendship concept. Syntactically, a class can become a friend of another class using the keyword, FRIENDS. Friendship is a one-sided relationship. In this example, the class lcl_2 is able to access the private attributes of the class lcl_1 after declaring it as a friend.

EXAMPLE OF A FACTORY CLASS

In this example, the public static method, create_airplane, either instantiates the class lcl_factory or returns a reference to an instance that already exists.

Tuesday, November 26, 2013

TAW12 - Object-Oriented Concept and Programming Techniques

EXAMPLE OF GENERALIZATION / SPECIALIZATION




As shown here, lcl_vehicle is a superclass; and lcl_car, lcl_truck, and lcl_bus are subclasses of the superclass. All the common properties of these subclasses are defined and implemented in the superclass. Therefore, from the perspective of a superclass, each subclass is a special part of a superclass containing properties that are both common as well as specific to it.
Specialization is often described as an “is a” relationship. In this example, you can say that “A truck is a specific vehicle.”
However, if we look at the same relationship from the perspective of a subclass, it is termed as generalization. This is because all subclasses contain the common properties defined in the superclass.


CHARACTERISTIC OF GENERALIZATION / SPECIALIZATION




Generalization or specialization offers an improved structure to the software, as commonly used elements are stored only once in a central location known as superclass. Components in a superclass are then automatically available to all the subclasses. You must know how to implement a superclass in order to determine whether the inherited components from the superclass are sufficient for the subclass, or if they need to be extended.
However, subclasses can be extended or changed as per the requirement.
Thus, there are very strong links between the superclass and the subclass, which are dependent on the superclass.

INHERITANCE - SYNTAX

Inheritance relationship is defined syntactically using the INHERITING FROM addition in the definition of a subclass, followed by the superclass name as shown in the slide. Superclass definition is the prerequisite for an inheritance relationship to be established. A subclass can access some of the properties of a superclass through inheritance. In this example, the subclass lcl_truck will also contain the superclass method set_type.


REDEFINING METHOD






Keyword REDEFINITION is used when the inherited methods from the superclass needs to be extended. However, the signature of the inherited method should not change.
If the keyword REDEFINITION is used, a new implementation part for that method must be specified. As shown here, in a redefined method’s implementation part, the keyword “super” can be used to access the components of the superclass.

PRESERVING SEMANTICS DURING REDEFINITION





As shown in the slide, the class lcl_bus and class lcl_truck both contain the method display_attributes; but the output of the method is different. Most importantly, the semantics of the method have not changed.

DEFINITION OF THE CONSTRUCTOR IN SUBCLASSES


Constructors in inheritance do not follow the same rules as the other instance methods when they are redefined. The constructor of the superclass can be used as it is or changed in the subclass, which means that the signature of the constructor can change.
However, it is compulsory to call the superclass constructor during its implementation in subclass.

RULES FOR CALLING THE CONSTRUCTOR



Let us look at the classes: lcl_1, lcl_2, and lcl_3. Objects go_2 and go_3 refer to the classes lcl_2 and lcl_3, respectively as shown. The class lcl_3 has a constructor with two parameters. Values to the constructor parameters can be supplied directly through the object as shown in case 1. However, if the constructor is an inherited one as in case 2, then you need to search the superclass constructor in the hierarchy. Subsequently, the values are supplied to the parameters.

INHERITANCE AND VISIBILITY



The visibility of the components of a class, which was restricted to Public or Private, is extended using inheritance. We now have protected components whose visibility lies between public and private. Components that are categorized as protected are visible to the class and all its subclasses.
However, when local classes are defined, the syntactical sequence followed for the visibility sections is: PUBLIC SECTION, PROTECTED SECTION, and PRIVATE SECTION.

PROTECTED VERSUS PRIVATE SECTION



We already know that the public components of a class can be accessed from outside; whereas the private components can only be accessed from within the class. Consider the class lcl_bus which inherits from the superclass lcl_vehicle. Here, mv_make and mv_model are private attributes of the class. Although they are inherited, they cannot be accessed directly. Therefore, lcl_bus only has public methods, constructor and display_attributes, as well as the protected attribute mv_color. These can only be accessed from inside.


STATIC COMPONENT : PROPERTIES



  All subclasses of a superclass can access its public or protected static attributes.

  Redefinition of static methods is not possible.

  When the superclass or one of its subclasses is accessed for the first time, the static constructor of a superclass is executed.

  A subclass can define a static constructor of its own irrespective of whether the superclass has one or not.

  If both subclass and superclass contain a static constructor, then both will be executed whenever the class is accessed for the first time.

UP-CAST (WIDENING CAST) WITH OBJECT REFERENCES


Let us say that the class lcl_truck is a subclass of the superclass lcl_vehicle. Object reference variables to both the classes are defined using the data statement. Using the statement go_vehicle = go_truck, we are assigning an object reference of type subclass to a superclass reference variable. After assignment, go_vehicle can access the inherited components in the subclass as shown. This is up-cast or widening cast.

STATIC AND DYNAMIC TYPE OF REFERENCES



The statement DATA go_vehicle TYPE REF TO lcl_vehicle creates a static reference variable. So a static reference variable
  is defined using the TYPE REF TO addition;

  remains same throughout; and

  specifies what attributes and methods can be accessed.

On the other hand, go_vehicle in the second diagram is a dynamic reference variable which
  is created by assignment;

  can change during the execution of a program; and

  specifies which attributes and methods can be implemented.

GENERIC ACCESS AFTER UP-CAST



With the help of cast assignments, generic access to the subclass components by a reference variable of type superclass is possible.
When a user is not at all interested in the finer points of the instances of the subclasses but simply wants to address the shared components, the user can make use of a superclass reference for this access.


ROLE TYPE IN THE INTERNAL TABLE IN THE APPLICATION EXAMPLE




In this example, objects of different classes, lcl_bus, lcl_truck, and lcl_car, have references of type superclass lcl_rental. Here, it is possible to store all these object references in an internal table.

UP-CAST AND GENERIC ACCESS IN THE APPLICATION EXAMPLE




This slide explains that up-cast assignment occurs when the vehicle reference is passed to the formal parameter of the add_vehicle method. Shared components can be accessed using the loop at the internal table containing all the vehicle references.

POLYMORPHISM: GENERIC ACCESS USING THE SUPER-CLASS REFERENCE


The output of the method display_attributes depends on the object to which the superclass reference variable – go_vehicle – points. As shown in the slide, the output of the method display_attributes is different in the two method calls.

GENERIC CALLS IN THE PROCEDURAL  PROGRAMMING MODEL


As shown here, gt_vehicles is a collection of vehicles in an internal table. The CALL FUNCTION statement inside the loop displays the properties of individual objects. This can also be done using a function group which contains different function modules.

DOWN CAST (NARROWING CAST) WITH OBJECT REFERENCES



In this example, the superclass reference variable go_vehicle is assigned to the subclass reference go_truck2. After this assignment, go_truck2 can access all the public components of lcl_truck as shown. This is defined as narrowing cast or down cast. The down-cast operator (?=) used in the process is shown in the example.

SPECIFIC ACCESS AFTER DOWN CAST ASSIGNMENT



All vehicle reference types are stored in an internal table that is typed as lcl_vehicle. You require down-cast assignment to address specific components of instances. It is also needed for keeping references of these instances in variables which are typed on the superclass.

DOWN CAST AND EXCEPTION HANDLING IN APPLICATION EXAMPLE



In down-cast assignment, if the static target reference is not type compatible with the source reference, exceptions can be raised. As shown in this example, the exception class – cx_sy_move_cast_error – which can raise the exception is caught using the CATCH statement within the TRY-ENDTRY block.


USAGE OF CLASS HIERARCHIES






If a generalization or specialization relationship is observed between certain classes, then inheritance can be used to represent this in ABAP Objects. There are various advantages of linking classes through inheritance concept:
  It allows for centralized maintenance.

  It enables safe and generic method of access.The software component can be easily extended.


EXAMPLE: MISUSE OF INHERITANCE

If the concept of “is a (specific)” is not understood properly, then the direction of inheritance could be easily misunderstood, which can be risky. For example, the class, car, has two subclasses, red and blue.
The statement “A red car is a specific car” may seem correct initially. This means every car must have the attribute Color, assuming that it is relevant to the application. Thus, the attribute has to be predefined in the superclass; otherwise, the authorizations for subclasses of this type are no longer possible. This may sound contradictory in a real life scenario.

CENTRAL DEFINITION OF SHARED COMPONENTS


An interface can simply be defined as a superclass that cannot be instantiated. This means that they do not have an implementation part. All the components of an interface are public. In ABAP Objects, the components which are defined in a superclass can be defined with interfaces. Let us look at an example to understand this.
As shown in the example here, the interface can be suitably modeled to provide appropriate services to the classes, lcl_carrier, lcl_hotel, and lcl_rental.

THE CLIENT DEFINES A PROTOCOL


Interfaces are like superclasses that do not have an implementation of their own. In an interface, a client defines the services that they expect different classes to perform. Each class can now decide whether it needs to implement the interface. This is similar to the specialization relationship with the superclass.

INTERFACE IN UML NOTATION


Interfaces are represented in the same way as classes in a UML notation. The name of the interface also contains the stereotype “«interface»” addition, which is optional. The use of an interface is shown by a dotted line with a two-sided arrow pointing from the user to the interface. A class implementing an interface is represented by a dotted arrow from the class to the interface.

DEFINING AND IMPLEMENTING INTERFACE

An interface is defined using the keyword INTERFACE followed by its name. Here, the interface contains a method display_partner. An interface does not have different visibility sections like classes. Therefore, all the components of an interface are public in nature. An interface is called in the method definition using the keyword INTERFACES, as shown. After the interface call, the methods of the interface can be implemented in the class definition. Interface method is implemented using the syntax, interface name, ‘tilde’ operator, followed by the method name, as shown. The tilde operator is also known as the interface resolution operator.

ADDRESING INTERFACE COMPONENT USING OBJECT REFERENCES


As shown in the slide, class lcl_rental implements the interface lif_partner. This interface (lif_partner) contains two methods, display_partner and check_availability. Components of an interface can only be accessed using an object reference of the class which implements the interface. Here, go_rental is the object reference of the class lcl_rental. The interface method can be called using the syntax, go_renta → lif_partner~display_partner ( ).

UP-CAST WITH INTERFACE REFERENCES



The class – lcl_rental – implements the interface – lif_partner – and can therefore access the methods of the interface. We have reference variables go_rental and go_partner of type class and interface, respectively. The object reference – go_rental – created using the data statement can access the public components of the class. When this object reference is assigned to a reference variable of type interface, interface reference variable can also access the interface components. This is up-cast using interfaces. However, after assignment, go_partner can only access the interface components.

ROW TYPE OF THE INTERNAL TABLE IN THE APPLICATION EXAMPLE


This slide depicts different classes, lcl_hotel, lcl_rental, and lcl_carrier, all of which refer to lcl_travel_agency. The objects of these different classes can be managed using an internal table of type lif_partner.
The components of the interface can be accessed uniformly using the method – add_partner – as its parameter is already typed as a reference to the interface.

POLYMORPHISM - GENERIC ACCESS USING THE INTERFACE REFERENCE


Interface references can be used to call methods, which give different outputs based on the object reference they point to. In this example, the implemented method – display_partner – displays different output depending on the object reference it refers to dynamically.

DOWN-CAST ASSIGNMENT AND EXCEPTION HANDLING IN THE APPLICATION EXAMPLE

At runtime, interface reference variables can point to instances of the implementing class. After this type of assignment, where a reference variable points back to a reference of the implementing class, access is not limited to the interface components. As shown here, all components of the lcl_carrier instance can be re-accessed after the assignment using reference r_carrier.

INTERFACE HIERARCHY IN THE APPLICATION EXAMPLE

Let us understand the extension of interfaces using this example. As shown here, both lcl_motel and lcl_hotel implement the interface, and request for a particular service which must be included in the interface. It cannot be defined individually for both. However, it should also be noted that there are several other objects already referring to the interface. Hence, it is a matter of debate whether an extension of this kind is appropriate.

COMPOUND INTERFACE IN UML NOTATION


This slide illustrates two interfaces, lif_partner and lif_lodging. As we all know, interfaces can include other interfaces. The including interface is known as a compound interface. The included interface is represented as a component of another interface and is, therefore, known as a component interface.

DEFINITION AND IMPLEMENTATION OF COMPOUND INTERFACE : SYNTAX



In this example, interface – lif_partner – is a component interface, and therefore, it is defined first. This interface is included or called in another interface – lif_lodging – using INTERFACES statement. Thus, the interface – lif_lodging – is now a compound interface. Class lcl_hotel implements the interface – lif_lodging. As it is a compound interface, lcl_hotel can also access display_partner, which is a method in the component interface. This is similar to how it can access method – book_room – in compound interface.

ADDRESSING COMPONENT IN COMPOUND INTERFACE - SYNTAX

Up-cast and down-cast assignments are possible with compound interfaces. In case of up-cast, after the cast assignment occurs, go_lodging can call the methods, display_partner and book_room. Similarly, go_partner can call display_partner method as shown. In the same way, specific methods can be accessed using down-cast assignment.


USING INTERFACE


When generalization or specialization relationships are created using an interface, it can help in
  defining protocol and services separately;

  allowing safe and generic method of access; and

  realizing multiple inheritances.

What all this means is that, the software can be extended easily.

EVENT-CONROLLED METHOD CLASS


Events, like attributes and methods, are components of a class. Events are of two types: Instance events and Static events. Instance events are triggered by the instances of the class, while static events are triggered by the class itself.
Whenever an event is triggered at runtime, the system calls for handler methods to respond to the event call.
In this example, creation of an instance in the “vehicle” class triggers the event “vehicle created.” This event is processed differently by different instances. For example, the car rental company considers purchasing a vehicle, while the vehicle registration office registers the car.


EVENT HANDLING IN A UML CLASS DIAGRAM



In UML notation, events are represented by a dotted arrow with the stereotype «handlesEventOf» pointing from the handling class to the triggering class. In the example shown here, lcl_rental is the handling class which handles the event – vehicle_created – triggered in raising class lcl_vehicle. The definition and signature of the event are defined in the handler method inside the handling class.

TRIGERING AND HANDLING EVENT - OVERVIEW

Instance events are defined with the keyword EVENTS; while static events are defined using the keyword CLASS-EVENTS. Objects of a class or the class itself can trigger the event using the RAISE EVENT statement. Once an event is triggered, it has to be handled. To handle a raised event, we can make use of a handler method of the handler class using the methods...FOR EVENT … OF …statement as shown; or by using a handler object with the SET HANDLER statement.

DEFINING AND TRIGERING EVENTS - SYNTAX

Instance events are defined using the EVENTS statement; while static events are defined using the CLASS-EVENTS statement. The signature of events can only have exporting parameters, which must be passed by value. A class or instance can trigger an event at runtime using the RAISE EVENT statement as shown.
Instance methods can trigger both instance events and static events; whereas static methods can only trigger static events.


HANDLING EVENTS - SYNTAX

Event handling by the instance or static method within a class requires FOR EVENT addition with the event name, along with the OF addition with the class or interface name. If the event has exporting parameters, then in order to pass values to these, you need to specify exporting parameters immediately after the keyword IMPORTING in the method definition.
In addition to the explicitly defined exporting parameters, the predefined importing parameter, sender, can always be listed. Using this parameter, you can place a reference to the event-trigger object into the handler method.


REGISTERING EVENT HANDLING

When an event is raised, it must be handled appropriately by a handler method. There can be many events which may be triggered. The handler method determines which event of which class method will react, and how it will react. At runtime, the system also determines which possible reactions will take place and at what time.
These specifications are collectively referred to as registration. It is always carried out using the trigger. The runtime makes use of the registrations of the trigger to determine which event handler methods need to be called.

REGISTERING EVENT HANDLING - SYNTAX


Events are only registered during the program runtime using the SET HANDLER statement. Syntactically in instance events, FOR addition is followed by the reference to the object that triggers the event. The addition – ACTIVATION 'X' – is optional during registration. Several methods can be registered with one SET HANDLER statement.


REGISTRATION/DEREGISTRATION: HANDLER TABLES


All events defined by an object or a class are stored in an internal table, also known as the handler table. This example shows handler table for two instances, ‘bus1’ and ‘bus2.’ All handler methods registered to the various events are listed within the table. The handler table also contains references to the registered objects in case of instance methods.

EVENTS: VISIBILITY SECTION


Events and event handler methods can be categorized as public, protected, or private on the basis of their visibility.
The visibility of an event determines where the event can be handled:
  PUBLIC events can be handled outside.

  PROTECTED events can only be handled within that class or its subclasses.

  PRIVATE events can only be handled within its class.

The visibility of a handler method determines the locations where the SET HANDLER statement can be programmed.
  If the handler is defined in PUBLIC SECTION, the SET HANDLER statement can appear anywhere in the program.

  If the handler is defined in PROTECTED SECTION, the SET HANDLER statement can appear within that class or its subclasses.

  If the handler is defined in PRIVATE SECTION, the SET HANDLER statement can only appear within its class.