Hi,
I will give you some basic idea regarding creating programs/applications in ABAP using OOP.
BACKGROUND: OOP has been around since c++ and java have been presented to the developers. Way back then ABAP is plainly a structured programming language which is similar to COBOL. But, today ABAP is now also capable of doing the full capability of OOP principles and designs started from the latest versions available in SAP.
To start with, developing programs in OO should adhere with the 4 basic principles of OOP. The ff. are:
1. ENCAPSULATION
2. ABSTRACTION
3. INHERITANCE
4. POLYMORPHISM
You should also apply the Design Principles which are:
1. OCP - encapsulate what varies
2. DRY - Code to an interface rather to an implementation
3. ARP or Single Responsibility Principle - each classes in your application should only have one reason to change
4. Liskov Substitution Principle - classes are about behavior and functionality
a. delegation - passing an object to another class in order for it to use the method of that delegated object
b. composition - whole part relationship.
- the whole class can not exist without the part i.e circle as to the point
c. aggregation - relationship between a whole class and its part, but the part can exist by their own. i.e plane and fuselage, cockpit etc relationship
You should be familiar also with the OOP design patterns like MVC and Singleton. Design patterns are doing a program by following a certain structure or flow/design depending on the nature of the application that you are doing. Design patterns have been around for so many years wherein you have to tailor your design. Actually it started with the architectural design. The objective of Design patterns is for the developers to have a pre-made coding/programming patterns to follow because those available patterns have already been tested and proven worked in different applications. Thus, if you are going to create an application for example with a user interaction, pulling data from the tables and showing the output to different kind of screens - then you may use Model View controller (MVC) design pattern for example.
I have also collected some of the ideas based on my experience for different types of classes in ABAP. the ff. are:
abstract class- a class that can be extended or can be a superclass
- it represents a model of the sub-classes
- its method can be redefined in its sub-classes
- its abstract method should be redefined in its sub-classes
- this can not be instantiated
- should atleast one abstract method
- not instantiated
- no implementation of method
- specific use of abstract like using it as a model with a generic code inside then create another class to inherit the abstract class to be able to use its code - using a super-> ABAP command.
- specific use of abstract like using it as a model with a generic code inside then create another class to inherit the abstract class to be able to use its code - using a super-> ABAP command.
interface class - all methods of the interface class act like an abstract class (though they should not show any "abstract" word upon declaration)
- any class that implements the interfaces should declare its methods within that class that implements
- cannot be instantiated
- no implementation of method
- not instantiated
final class - class that can not be extended further
event method - compose of triggers and handlers
- triggers are methods of a class that fire the events
- while handlers are method of a class or other classes that receives the signal if the event has been triggered. Once triggered, each handlers should act accordingly.
- handlers are set through SET HANDLER command
- set handler h FOR c where c is the object name, it only reacts for the particular class or object that raises
- set handler h FOR ALL INSTANCES if you want the handler to react for every raise of the event in every class that raises it
You may also want to check this link.
No comments:
Post a Comment