Skip to end of metadata
Go to start of metadata

Difference between class and a function module?

  Ans. Function modules are ABAP routines that are administered in a central function library. They apply across applications and are available throughout the system. You must assign function modules to a function pool that is called a function group. A function group is nothing but a container for the function modules. 
Classes are templates for objects. Conversely, you can say that the type of an object is the same as its class. A class is an abstract description of an object. You could say that it is a set of instructions for building an object. The attributes of objects are defined by the components of the class, which describe the state and behavior of objects.

What is wrapper class?

 A data structure or software that contains ("wraps around") other data or software, so that the contained elements can exist in the newer system. The term is often used with component software, where a wrapper is placed around a legacy routine to make it behave like an object. This is also called "encapsulation" or "wrapper encapsulation," but is not the same as "object encapsulation," a fundamental concept of object technology.  
What are events in classes?

Triggering Events

To trigger an event, a class must

-         Declare the event in its declaration part

-         Trigger the event in one of its methods

Declaring Events

You declare events in the declaration part of a class or in an interface. To declare instance events, use the following statement:

EVENTS <evt> EXPORTING... VALUE(<ei>) TYPE type [OPTIONAL]..

To declare static events, use the following statement:

CLASS-EVENTS <evt>...

Both statements have the same syntax.

When you declare an event, you can use the EXPORTING addition to specify parameters that are passed to the event handler. The parameters are always passed by value.  Instance events always contain the implicit parameter SENDER, which has the type of a reference to the class or the interface in which the event is declared.

Triggering Events

An instance event in a class can be triggered by any method in the class. Static events can be triggered by any static method.  To trigger an event in a method, use the following statement:

RAISE EVENT <evt> EXPORTING... <ei> = <fi>...

For each formal parameter <e i> that is not defined as optional, you must pass a corresponding actual parameter <f i> in the EXPORTING addition.  The self-reference ME is automatically passed to the implicit parameter SENDER.

Handling Events

Events are handled using special methods.  To handle an event, a method must

-         be defined as an event handler method for that event

-         be registered at runtime for the event.  
Difference between global and local class? 
 Local and Global Classes

Classes in ABAP Objects can be declared either globally or locally. You define global classes and interfaces in the Class Builder (Transaction SE24) in the ABAP Workbench. They are stored centrally in class pools in the class library in the R/3 Repository. All of the ABAP programs in an R/3 System can access the global classes. Local classes are defined within an ABAP program. Local classes and interfaces can only be used in the program in which they are defined. When you use a class in an ABAP program, the system first searches for a local class with the specified name. If it does not find one, it then looks for a global class. Apart from the visibility question, there is no difference between using a global class and using a local class.

There is, however, a significant difference in the way that local and global classes are designed. If you are defining a local class that is only used in a single program, it is usually sufficient to define the outwardly visible components so that it fits into that program. Global classes, on the other hand, must be able to be used anywhere. This means that certain restrictions apply when you define the interface of a global class, since the system must be able to guarantee that any program using an object of a global class can recognize the data type of each interface parameter.   
 Difference between static method and instance method?

Instance Methods

You declare instance methods using the METHODS statement. They can access all of the attributes of a class, and can trigger all of the events of the class.

Static Methods

You declare static methods using the CLASS-METHODS statement. They can only access static attributes and trigger static events.

What is friend class?

In object-oriented programming to allow access to "private" or "protected" data of a class in another class, the latter class is declared as a friend class.

Purpose

A friend class has full access to the private data members of a class without being a member of that class.

 Example

A friend class can be declared as shown:

class A

Unknown macro: { private}

  
What is static constructor and instance constructor? 
Static constructor is used to initialize static data members as soon as the class is referenced first time, whereas an instance constructor is used to create an instance of that class with <new> keyword. A static constructor does not take access modifiers or have parameters and can't access any non-static data member of a class.

Since static constructor is a class constructor, they are guaranteed to be called as soon as we refer to that class or by creating an instance of that class.

You may say, why not initialize static data members where we declare them in the code. Like this :

private static int id = 10;
private static string name = "jack";

Static data members can certainly be initialized at the time of their declaration but there are times when value of one static member may depend upon the value of another static member. In such cases we definitely need some mechanism to handle conditional initialization of static members.    What is abstract class?

A class without a instance is abstract classes. Consists of abstract methods whose implementation is to be provided by the user itself. Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation. Abstract classes may not be instantiated, and require subclasses to provide implementations for the abstract methods.  
What is overriding polymorphism?

Method overriding, in object oriented programming, is a language feature that allows a subclass to provide a specific implementation of a method that is already provided by one of its super-classes. The implementation in the subclass overrides (replaces) the implementation in the super-class.

A subclass can give its own definition of methods which also happen to have the same signature as the method in its super-class. This means that the subclass's method has the same name and parameter list as the super-class's overridden method. Constraints on the similarity of return type vary from language to language, as some languages support covariance on return types.

Method overriding is an important feature that facilitates polymorphism in the design of object-oriented programs.

Some languages allow the programmer to prevent a method from being overridden, or disallow method overriding in certain core classes. This may or may not involve an inability to subclass from a given class.

In many cases, abstract classes are designed — i.e. classes that exist only in order to have specialized subclasses derived from them. Such abstract classes have methods that do not perform any useful operations and are meant to be overridden by specific implementations in the subclasses. Thus, the abstract super-class defines a common interface which all the subclasses inherit.

  • No labels