Object Oriented Programming in ProvideX

The ProvideX language has been extended to support all of the key design principles of Object Oriented Programming (OOP). Various OOP-related articles and examples are available from the ProvideX website (www.pvx.com).


The three basic principles of OOP are Encapsulation, Inheritance, and Polymorphism. These concepts provide a major part of the framework used to create and interact with objects. ProvideX OOP objects are defined through the use of classes. A class defines the name given to the object definition, as well as the object's properties and methods. Properties are the data portion of the object, consisting of fields or variables. Methods (or functions) are the actions that the object will perform. The defined properties/methods are accessible via the Apostrophe Operator.


Directives and Functions used to handle OOP mechanisms in ProvideX

DEF CLASS

Use the DEF CLASS directive in Object Oriented Programming (OOP) to declare the start of an object definition. It defines the name of the object and it can be used to override object creation and deletion logic.


class$ specifies the class name that will refer to this type of object. Class names are case-insensitive and forward/backward slashes are considered equivalent. Duplicate names are not allowed within the system. An object declared as UNIQUE will have a single instance created, and any subsequent attempt to create an instance returns the same object identifier and increments the object reference count by one.


By default, an object can have ON_CREATE and/or ON_DELETE logic defined. You can override this by specifying new label names for the creation/deletion logic via CREATE label and DELETE label clauses in the class definition. Normally, object creation/deletion logic is invoked when an object of this specific class is created/destroyed. That means, if you have ON_CREATE logic for an object A and object B inherits it, then the ON_CREATE for object A will not be executed on creation of object B. You can force creation and/or deletion logic to be executed on inheritance by including the keyword REQUIRED.


In terms of precedence, if an object inherits another object that has creation logic, the creation logic for the inherited object is performed first; e.g., if object C inherited object B which inherited object A, then the ON_CREATE in object A would be performed first, followed by object B's and finally object C's. (Deletion logic is performed in the opposite order).

PROPERTY

The PROPERTY directive is used in Object Oriented Programming to declare the properties that can be accessed by the application program. These properties can be treated like any other variable in the system and are accessible using the Apostrophe Operator.

LOCAL

The LOCAL directive is used to reassign variable names temporarily within a called procedure, without affecting the original contents (if any). In Object Oriented Programming (OOP), the LOCAL directive is similar to the PROPERTY directive, but is used to declare data that is only visible to processing logic within the object itself.

FUNCTION

The FUNCTION directive is used to declare a method for an object in Object Oriented Programming (OOP). Associated logic is to be called when the method is invoked.

LIKE

The LIKE directive is used in Object Oriented Programming (OOP) to inherit the properties from one or more other classes. All properties and methods are inherited from the specified classes.

STATIC

In Object Oriented Programming (OOP), the STATIC directive is used to create variables for use within an object at runtime -- basically, STATIC is used to extend the list of LOCAL properties. This allows for the dynamic creation of variables which are visible to operations within an object, yet which are not directly accessible to outside code.

DROP OBJECT

The DROP OBJECT directive is used in Object Oriented Programming to delete an object.

NEW( )

The NEW( ) function is used in Object Oriented Programming to create a new object based on a specified class name or an existing object (obj_id). If the class name already exists, then its definition is used. If it has not been defined previously, the system attempts to load the program class.pvc and execute/define the DEF CLASS within it (the DEF CLASS clause must be at the start of the program). If the system is unable to properly determine the class definition, an Error #90:"Unable to locate Object class definition" is generated.

REF( )

The REF ( ) function is used in Object Oriented Programming to control access to an object by incrementing or decrementing the reference count.