Page 2 of 2

Re: The ability to Create non-visual Classes

Posted: Mon Dec 13, 2010 8:07 pm
by Trond
PMV wrote:
Trond wrote:Interfaces make it difficult to allow instances to override methods.
The vtable points to a list of pointers to the procedurs. If you want to change the
call of one procedure, you only need to override this single pointer. That is the same,
if you want to override the pointer of a prototype.

MFG PMV
Normally you would place the vtable in the datasection, and it will be shared by all instances. Overriding a method for all instances is still simple, but overriding a method for just one instance is not.

Re: The ability to Create non-visual Classes

Posted: Mon Dec 13, 2010 8:41 pm
by PMV
i never have used a vTable pointing to a DataSection :lol:
I have always created a constructor like this:

Code: Select all

Interface MyClass
  Shout(Msg.s)
EndInterface

Structure MyClass_Struc
  vTable.i
  *Shout
  
  Name.s
EndStructure


Procedure MyClass_Shout(*Self.MyClass_Struc, Msg.s)
  MessageRequester("Shout!", Msg + " from " + *Self\Name + "!")
EndProcedure

Procedure MyClass(Name.s)
  Protected *Self.MyClass_Struc = AllocateMemory(SizeOf(MyClass_Struc))
  InitializeStructure(*Self, MyClass_Struc)
  *Self\vTable = *Self + SizeOf(INTEGER)
  *Self\Shout = @MyClass_Shout()
  *Self\Name = Name
  ProcedureReturn *Self
EndProcedure


Bill.MyClass = MyClass("Bill")
Bob.MyClass = MyClass("Bob")

Bill\Shout("Hello world!")
Bob\Shout("Goodbye, world!")
Looks like your example with Prototypes, but a little bit better.
:D

MFG PMV