PureBasic and the Object-Oriented Programming Interface instruction
The PureBasic Interface instruction allows grouping under the same Name (< Name1 > in the above box) various procedures. Ex :
By declaring an element of My_Object, the access to its procedures
looks like as follows.
Using the Interface instruction leads to a very practical and pleasant
notation to operate a procedure. Initialization: As unexpected, by giving the name of a procedure inside the Interface:EndInterface block you don't refere to the implementation of the procedure, e.i. to refer to the Procedure:EndProcedure block of the wished procedure. In fact, you can rename procedures inside a Interface:EndInterface block, by giving the names you want for the procedures that you go to use. Then, how to connect this new name with the wished procedure? As for overloaded methods, the solution is in the function addresses. However, to initialize the function pointers of an Interface specified
element, it is necessary to process differently than for a Structure
specified element. The initialization comes indirectly by giving to the element, the address of a initialized variable storing the function pointers. A such variable is called: the table of the methods. Ex: by resuming the Interface My_Object, let us consider the following Structure describing the function pointers:
and the associated table of the methods:
where My_Procedure1() and My_Procedure2() are the wished procedure implementations. Then, the initialization of Object from Interface My_Object looks like this:
Next, by writing
the Object Procedure2() function is called according My_Procedure2() implementation.
To summarize, using an Interface involve:
and the properties are:
|
Dräc - 2005 |