Start of Content Area

Background documentation Using ABAP Objects - Best Practices  Locate the document in its SAP Library structure

Program as defensively as possible: Access to the elements of classes should be as restrictive as possible and exceptions should only be made in individual, justified cases. The less code you expose to the outside, the more freedom you have for adapting or optimizing the implementation of your classes to suit your needs.

·        Declare classes as FINAL.

·        If working with public attributes, declare them as READ-ONLY.

·        Keep the number of public attributes to a minimum.

·        Any methods that can be private should also be declared as such.

·        For internal services, use local classes in class pools. In the case of self-contained services, this is preferable to private methods of a global class.

·        Use inheritance sparingly. If you are unsure, use interfaces to achieve polymorphism.

·        It is better to use instance methods in local singletons than class methods: In this way, you can control instantiation and lifetime.

·        If you require loose coupling, use events. Do not try to implement it yourself.

·        Limit the lifetime of your variables, as much as the relevant program allows. Local variables have a shorter lifetime than instance variables, which in turn are more short-lived than class variables.

 

End of Content Area