Know the difference between Class and Function Module

 
Page restrictions apply Added by Zahack, last edited by Zahack on Feb 07, 2009

view

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>...

There is. a significant difference in the way that local and global classes are designed. a method must be defined as an event handler method for that event be registered at runtime for the event. They can only access static attributes and trigger static events. 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. If you are defining a local class that is only used in a single program. This means that certain restrictions apply when you define the interface of a global class. The self-reference ME is automatically passed to the implicit parameter SENDER. Example A friend class can be declared as shown: class A Unknown macro: { private} What is static constructor and instance constructor? . When you use a class in an ABAP program. Handling Events Events are handled using special methods. it is usually sufficient to define the outwardly visible components so that it fits into that program. you must pass a corresponding actual parameter <f i> in the EXPORTING addition.For each formal parameter <e i> that is not defined as optional. Difference between global and local class? Local and Global Classes Classes in ABAP Objects can be declared either globally or locally. What is friend class? In object-oriented programming to allow access to "private" or "protected" data of a class in another class. They are stored centrally in class pools in the class library in the R/3 Repository. Local classes and interfaces can only be used in the program in which they are defined. must be able to be used anywhere. Apart from the visibility question. All of the ABAP programs in an R/3 System can access the global classes. They can access all of the attributes of a class. Local classes are defined within an ABAP program. To handle an event. Purpose A friend class has full access to the private data members of a class without being a member of that class. however. the system first searches for a local class with the specified name. on the other hand. there is no difference between using a global class and using a local class. the latter class is declared as a friend class. Static Methods You declare static methods using the CLASS-METHODS statement. You define global classes and interfaces in the Class Builder (Transaction SE24) in the ABAP Workbench. Global classes. Difference between static method and instance method? Instance Methods You declare instance methods using the METHODS statement. it then looks for a global class. If it does not find one. and can trigger all of the events of the class.

but contains no implementation.Static constructor is used to initialize static data members as soon as the class is referenced first time.e. A subclass can give its own definition of methods which also happen to have the same signature as the method in its superclass. Method overriding is an important feature that facilitates polymorphism in the design of object-oriented programs. A static constructor does not take access modifiers or have parameters and can't access any non-static data member of a class. why not initialize static data members where we declare them in the code. Abstract classes are classes that contain one or more abstract methods. Since static constructor is a class constructor. Some languages allow the programmer to prevent a method from being overridden. 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 many cases. Such abstract classes have methods that do not perform any useful operations and are meant to be overridden by specific implementations in the subclasses. Consists of abstract methods whose implementation is to be provided by the user itself. or disallow method overriding in certain core classes. Like this : private static int id = 10. abstract classes are designed — i. This means that the subclass's method has the same name and parameter list as the super-class's overridden method. The implementation in the subclass overrides (replaces) the implementation in the super-class. classes that exist only in order to have specialized subclasses derived from them. Constraints on the similarity of return type vary from language to language. This may or may not involve an inability to subclass from a given class. the abstract super-class defines a common interface which all the subclasses inherit. they are guaranteed to be called as soon as we refer to that class or by creating an instance of that class. In such cases we definitely need some mechanism to handle conditional initialization of static members. Thus. An abstract method is a method that is declared. as some languages support covariance on return types. What is overriding polymorphism? Method overriding. What is abstract class? A class without a instance is abstract classes. Abstract classes may not be instantiated. You may say. . and require subclasses to provide implementations for the abstract methods. whereas an instance constructor is used to create an instance of that class with <new> keyword. 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. private static string name = "jack".