REPOSITORY. CLASS Foobar IS 'Foobar'.For a method, the REPOSITORY paragraph belongs in the class definition rather than in the method definition itself.
01 GENERIC-OBJ USAGE IS OBJECT REFERENCE VALUE NULL. * 01 FOOBAR-OBJ USAGE IS OBJECT REFERENCE Foobar VALUE NULL.In the example above, GENERIC-OBJ is a universal object reference. It may refer to any object. FOOBAR-OBJ, however, is restricted to objects of the class Foobar, or of classes derived from Foobar. In each case the VALUE clause initializes the object reference so that it doesn't point to anything.
Object references may occur in the WORKING-STORAGE SECTION, the LOCAL-STORAGE SECTION, or the LINKAGE SECTION. Presumably they may appear in the FILE SECTION as well, but not usefully. Like a pointer, an object reference is meaningful only during a particular execution of the program.
INVOKE FOOBAR-OBJ 'displayOnSysout' USING INDENTATION-DEPTH.I won't try to list all the possible variations. Suffice it to say that an INVOKE works much like a CALL, and offers pretty much the same options, except that you have to provide an object reference to identify the object whose method you are invoking.
Depending on compile-time options, the compiler may optionally consult the Interface Repository (IR) to verify that you are passing the right kinds of parameters to the method.
SET GENERIC-OBJ TO FOOBAR-OBJ.You can also detach a reference from its object:
SET FOOBAR-OBJECT TO NULL.Within a method definition, you can attach a reference to the object whose method you are defining:
SET FOOBAR-OBJ TO SELF.
INVOKE Foobar 'somNew' RETURNING FOOBAR-OBJ.At first glance, this syntax appears different from the kinds of INVOKEs described above. You can't specify a Foobar which doesn't exist yet, so you specify the class instead.
Actually this syntax is less different than it appears. Foobar is an object. It is an instance of the class SOMClass (which is an instance of itself). The method somNew is not a method of Foobar -- it is a method of SOMClass. The real difference is that we don't need an object reference to the Foobar class. The REPOSITORY paragraph serves the same function instead.
When you're through with an object, you should destroy it:
INVOKE FOOBAR-OBJ 'somFree'.This time you specify the object, not the class.
Unfortunately somInit accepts no parameters. Left to its own devices, it will initialize each instance of a given class in exactly the same way. In practice you generally want to initialize different instances differently. It's up to you to come up with a way to do so.
When somFree destroys an object, it invokes the somUninit method for the last-derived class, if one is defined. Then it invokes the somUninit methods for all the base classes, from the bottom up -- in the reverse of the order in which somNew invoked the corresponding somInit methods.
You are expected to override somInit and somUninit as needed. In particular, somUninit provides a way to automatically release any resources which may be associated with an object -- such as files, dynamically allocated memory, or other objects.