Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all articles
Browse latest Browse all 935

Key Points Of OOP & Sample Code

$
0
0

Key Points Of Object Oriented Programming

 

          Hi, most of the people here on SCN try to learn object oriented programming through various available sources. I have also tried a lot to learn this beautiful OOP feature and still learning it. Even I have gone through various SAP Press Books to summarize all the aspects of it. Here I have prepared a small set of information that would be useful before, after and in-between phase of learning OOP. It also helps you to get quick understanding of any topic before you go in depth. I have not explained global class here that is skipped intentionally for your practice with reference to local class. Please check all sample abap code. As I said I am also learning so I may not give you some of your queries so please bear with me and help me to improve this document so that everyone can get benefit from it. I always try to provide best details to you if possible. Thank you.

 

Class

A class is an abstract representation, or, a set of instructions for building objects

Object

Objects are instances of classes. There can be any number of objects or instances in a class. Each object has a unique identity and its own attributes.

Encapsulation

Visibility (public, protected, private)

Inheritance

Inheritance allows you to derive a new class from an existing class.

Polymorphism

Overriding methods / redefining method - after inheriting / Interface.

Abstract

Definition of a class cannot generate instance. You can only 

        Use an abstract class to create subclass.

Friend-Deferred

Access private attributes of another class.

Event

Invoke methods of same or other class.

Interface

Cannot have implementation, just the definition.

Exception

Static check-(check both at runtime and compile time), Dynamic check (only checks at runtime), No check (for all kind of exceptions). using CX_ROOT class

Levels

Instance, static, Constant.

Test class / Test methods

unit test (Test method class CL_AUNIT_ASSERT, #AU_DURATION_SHORT, #AU_RISK_LEVEL HARMLESS)

Persistent Class

Agent class, Base class, Class.

Refactoring Assistant

Add new class above any existing class.

Serialization

Transformation of ABAP data in an XML document. Either by calling a XSLT program or a simple transformation. When using XSLT, the system first generates a canonical XML representation (asXML).

Object parameters

Importing/Exporting/Returning-(receiving)/Exception and Raising

 

 

Additional Points.

->Static data shares common value across any number of its object, and it is only accessible inside static method and it is accessible via => operator (cls_name=>static attribute).

 

->Multiple inheritance is not supported by abap (we may use interface to achieve this).

 

->In object parameter: Exception is non-class base exception which is triggered with statement raise / message raising.

 

->In object parameter: Raising is class base exception which is triggered with statement raise / message raising.

 

 

-> Protected section will become private in successor class once it is inherited from parent.

 

->The tilde (~) between the interface name and the interface component name is called the interface component selector operator.

 

->In persistent the class builder also generates a couple of additional agent classes that manage all of the low-level interaction details between objects of the persistent class and the Persistence Service.


->objects of persistent classes are referred to as managed objects.

 

->Transaction persistent service (We can insert data directly from persistent class to dB table using Tcode). IF_OS_TRANSACTION & IF_OS_TRANSACTION_MANAGER

 

->Transaction for a local class method

 

->XML Transformation using Tcode xslt_tool to generate xml files.

 

 

General OOP Course Content that you should know:

 

  1. Class and object creation.
  2. Encapsulation (Public, Protected, Private).
  3. Constructor.
  4. Class method / class data.
  5. Final class - cannot be inherited any more.
  6. Final method - cannot be redefined any more.
  7. Inheritance.
  8. Using of super keyword.
  9. Interface.
  10. Exception handling using cx_root class.
  11. Test methods.
  12. Persistent class.
  13. Refactoring assistant.
  14. Serialization- XML Transformation.
  15. MVC pattern.

 

Program Samples Index.

  • Class
  • Encapsulation
  • Inheritance
  • Polymorphism
  • Super keyword
  • Abstract
  • Friend-Deferred
  • Event
  • Interface
  • Exception
  • Test class / Test methods
  • Object parameters - Part 1
  • Object parameters - Part 2
  • MVC Pattern

 

Program Samples.

 

     1.Class.

 

     2. Encapsulation.

 

 

     3. Inheritance

 

               

 

     4.Polymorphism

                  

 

     5.Super keyword

       

 

     6.Abstract

 


 

 

 

 

     7.Friend-Deferred

 

 

 

     8.Event

 

               

     9.Interface


 

 

     10.Exception

 

    

     11.Test class / Test methods

*How to execute this type of test: from menu path Program->Test->Unit Test.

 



 

 

 

     12.Object parameters - Part 1

 



 

 

     13.Object parameters - Part 2 (Exception and Raising)


     A. Raising->Automatic error handling.

 

 

                  

 

 

 

 

 

 

 

 

     B. Exception->manually error code assign and handle.

 

          

     14.MVC Pattern

 

        

 

 

- Avirat


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>