Built in Object Oriented Programming Model

Unlike previous models this does not rely on user defined macros. It uses virtual tables and pointers in a similar manner to COM. OOP is built into the Asmosphere preprocessor, taking care of all the tricky bits.

This model also supports multiple inheritance - ie a class can have several ancestors.

The extra notation required is minimal. In fact the words class and object are not used at all. The system is an extension of type.

To declare a class, the type statement is divided into 2 parts: The first part contains methods, inherited structures and class static members. The second part contains the set of properties assigned to each object, (inherited properties are automatically appended)

This is a class defined in a single line: ! denotes a method. / divides the two parts of the class, and inherited types must be followed by a comma as usual.

type classAB classA, classB, 4 methodA! 4 methodB! 4 MethodC! membA / 4 vft 4 va 4 vb 4 vc

this is immediately followed by a scoped class builder and a set of methods

(
build classAB
exit
var ClassAB this

methodA:
...
ret 4

methodB:
...
ret 4

...

)


to create an object:

var ClassAB myObject
myObject.vft=&ClassAB_table


which gives us an empty object except for its virtual table pointer, which allows the object to call any of its methods, (including inherited methods)


edx=myObject.methodA ...

Because all the methods are defined inside the brackets, they are not visible to the rest of the program.

Below is a simple piece used to test the basic functionality of the model. To use it you will need the new Oxygen:

http://community.thinbasic.com/index.php?topic=1845.0


[code=thinbasic]
' OOP with virtual tables


uses "OXYGEN"
uses "FILE"

dim vv as long
dim src as string

src="
indexers `esi` offset 0 ascending
esi=dataspace 0x100
type ClassA 4 a1! 4 a2! 4 fstatic / 4 pvft 4 pep 4 pip
(
build ClassA
exit
var classA this
a1:
this=&ClassA_Table
ret 4
a2:
this=&ClassA_Table
inc this.pip
ret 4
)
type ClassB 4 b1! 4 b2! / 4 pvft 4 pep 4 pip
(
build ClassB
exit
var classB this
b1:
this=&ClassB_Table
mov eax,66
ret 4
b2:
this=&ClassB_Table
inc this.pip
ret 4
)
type classAA classA, 4 fna! 4 fnb! 4 fnc! 4 fstatic classB, / 4 pvft 4 aa 4 bb
(
build classAA
exit
var ClassAA this
o2 /+4
fna:
this=&ClassAA_Table
inc this.aa
[#vv]=sizeof ClassAA
ret 4
fnb:
this=&ClassAA_Table
ret 4
fnc:
this=&ClassAA_Table
ret 4
)
var classAA myobject
myobject=&ClassAA_table


ecx=myobject.fna ; test method fna
ecx=myobject.fnb ; test method fnb
[#vv]=myobject.b1 ; test inherited method
ret

"
'msgbox 0,o2_view (src)
o2_asmo src
if len(o2_error) then
msgbox 0,"OOP1: "+o2_error()+o2_view (src)
stop
end if
o2_exec
msgbox 0,"0x"+hex$(vv)


[/code]