Page 1 of 1

Recognized Interface returned by Interface Methods

Posted: Wed Aug 29, 2012 10:33 pm
by grabiller
Hi,

When defining an Interface, the compiler does not accept a method returning the same interface. It says "a Procedure can't return a Structure".

But an instanciated Interface is a pointer.

Of course we can work around by declaring de method returning a 'i'. But this way we can't chain methods calls, the compiler won't recognize those and will generate an error.

For instance :

Code: Select all

; with:
Interface MyClass
  DoSomething.MyClass()
  DoSomethingElse.MyClass()
EndInterface

oC.MyClass = New_MyClass() ; granted you've created this Procedure to create the instance.

; then we could do something like that:
oC\DoSomething()\DoSomethingElse()

; instead of
oC\DoSomething()
oC\DoSomethingElse()

Or perhaps it's allready possible and I've missed something ?

Cheers,
Guy.

Re: Recognized Interface returned by Interface Methods

Posted: Thu Aug 30, 2012 11:30 am
by srod
Ah well, that code you've posted doesn't make sense unless the \DoSomething() method returns another instance of the same class? You are essentially correct though in that this kind of thing is not possible.

The thing is of course that PB would need to step up its garbage collection before it could offer this kind of 'chaining' of method calls etc. Not sure that Fred would want to go down that path.

Re: Recognized Interface returned by Interface Methods

Posted: Thu Aug 30, 2012 1:49 pm
by grabiller
srod wrote:Ah well, that code you've posted doesn't make sense unless the \DoSomething() method returns another instance of the same class?../..
Exactly, that's why in my exemple 'DoSomething()' is declared this way in the 'MyClass' interface: DoSomething.MyClass()

It means it is supposed to return an instance of the same class. But the compiler 'thinks' the method would return a Structure, so it does not allow this syntax.

Cheers,
Guy.

Re: Recognized Interface returned by Interface Methods

Posted: Thu Aug 30, 2012 2:15 pm
by BorisTheOld
srod wrote: The thing is of course that PB would need to step up its garbage collection before it could offer this kind of 'chaining' of method calls etc. Not sure that Fred would want to go down that path.
Reference counting and garbage collection can be handled already, but it needs a few lines of code added to each class. Also, objects need to be created, destroyed, and cloned in a particular way.

Here's what a typical application looks like - DvsML06 is the class name of the application:

Code: Select all

.
.
an IncludeFile for each class that is used in the application
.
.
  GlobalObject(gloDvsML06, objDvsML06)
  gloDvsML06 = CreateObject(DvsML06) (gloDvsML06)
  ObjectCall(gloDvsML06, Main) ()
  gloDvsML06 = ObjectReturn(gloDvsML06, Destroy) ()

End
This translates to:

Code: Select all

  Global gloDvsML06.objDvsML06
  gloDvsML06 = clsDvsML06_funCreate(gloDvsML06)
  gloDvsML06\subMain()
  gloDvsML06 = gloDvsML06\funDestroy()
The Create, Destroy, and Clone methods of a class do all the memory management, and only takes about 50 lines of code per class. And except for the above code, all other application code is written in the form of classes.