In this context, abstractions are a simplified representations of complex relationships in the real world. An actually existing object is abstracted to the significant dimensions that are to be mapped. Insignificant details are left out in order to aid understanding of the overall system.

This example concerns airplanes. Software for airlines and software for an airport’s hangar management contain different abstractions (classes) for these objects.

A class can contain very different objects depending on the abstraction.

A class is a description of a number of objects that have the same structure and the same behavior. A class is therefore like a blueprint, in accordance with which all objects in that class are created.

The components of the class are defined in the definition part. The components are attributes, methods, events, constants, types and implemented interfaces. Only methods are implemented in the implementation part.

The CLASS statement cannot be nested, that is, you cannot define a class within a class.

Attributes describe the data that can be stored in the objects in a class.

Class attributes can be of any type:
­ Data types: scalar (for example, data element), structured, in tables
­ ABAP elementary types (C, I, ...)
­ Object references
­ Interface references

Attributes of the airplane class are, for example:
­ Name
­ Seats
­ Weight
­ Length
­ Wings
­ Tank

In classes, you can only use the TYPE reference to refer to data types in the ABAP Dictionary.

You can only use the LIKE reference for local data objects.

The READ-ONLY addition means that a public attribute declared with DATA can be read from outside, but can only be changed by methods within the class.

You can currently only use the READ-ONLY addition in the public visibility section (PUBLIC SECTION) of a class declaration or in an interface definition.

You can protect attributes against access from outside by characterizing them as private attributes (defined in the PRIVATE SECTION).

Attributes and their values that may be used directly by an external user are public attributes and are defined in the PUBLIC SECTION.

In the above example for class lcl_airplane, the name attribute is initially defined as a public attribute and the weight attribute is defined as a private attribute.

Public attributes belong to the class ‘external point of contact’ that is, their implementation is publicized. If you want to hide the internal implementation from users, you must define internal and external views of attributes.

As a general rule, you should define as few public attributes as possible.

There are two kinds of attributes
­ Static attributes
­ Instance attributes

Instance attributes are attributes that exist separately for each object.
Instance attributes are defined using the DATA keyword.

Static attributes exist once only for each class and are visible for all (runtime) instances in that class. Static attributes usually contain information that is common to all instances, such as:

­ Data that is the same in all instances
­ Administrative information about the instances in that class (for example, counters and so on)
­ Static attributes are defined using the CLASS-DATA keyword.

You may come across the expression “class attributes” in documentation, however, the official term in ABAP Objects (as in C++, Java) is “static” attributes.



No comments :

Post a Comment