Object Interdependencies

One of the major issues facing object oriented programming is keeping track of objects libraries as they get loaded. Leaving instances of unwanted or unneeded objects ties up system resources. In addition, objects themselves often allocate additional resources such as files behind the scenes. Forgetting to drop these objects when no longer needed can often ultimately cause your application to fail.

The problem facing most application developers using Objects is:

How can I avoid leaving objects hanging around in the system?

The enhanced OOP interface included in PxPlus helps to answer this question and solve the problem by allowing the programmer to associate the existence of new objects to other system components, such as, Programs, Windows, Controls, Files and other Objects. As these other components are closed or deleted, the associated objects will automatically have their usage count decremented in effect causing them to also be deleted at the same time (This assumes no other reference to the object exists).

This feature allows programmers to leave much of the housekeeping logic related to objects up to the system, as opposed to having to worry about coding for it themselves. By linking objects to the current program, when the program exits the object will be dropped. By linking an object to the current window, closing the windows frees both the resources allocated to the window and the associated object(s).

To establish an association the NEW function has been enhanced to include a "FOR" option where the programmer can specify the component that will be linked to the object.

Syntax:

objId = NEW("..object..", args,.. FOR WINDOW)
objId = NEW("..object..", args,.. FOR CONTROL <ctlid>)
objId = NEW("..object..", args,.. FOR FILE <fileno>)
objId = NEW("..object..", args,.. FOR OBJECT [ <objid> ])
objId = NEW("..object..", args,.. FOR PROGRAM)

Where:

<ctlid> is the control identifier that the new object will be associated with.
<fileno> is the file number that the new object will be associated with.
<objid> is an optional existing object to associate the new object to.