[Gambas-user] An other problem with object oriented approach.

Jussi Lahtinen jussi.lahtinen at ...626...
Sat Dec 13 18:54:04 CET 2008


Hi!

I'm converting Vb6 project to Gambas.
And because Gambas doesn't have UDT/structures, I have to rethink some
of the code (not necessary bad thing).
I'm converting some parts of the code to object oriented way.
But I run into some problems with it.
I have module which contains mainly global arrays and global UDT arrays.
That module describe items, every item is identified by index number.
Like this (vb6 code):
Global Alive(Max_Number_Of_Items)  as boolean

So if I want to know if item 2 is alive, I'll write:
IF Alive[2] = TRUE THEN

Problem is in identification, items have to know who is who.
Old array based code is something like this:

IF Alive[Who] = TRUE THEN
ComWith = CommunicateWith[Who]
  IF Alive[ComWith] = TRUE THEN
  WhereX[ComWith] = ...
  WhereY[ComWith] = ...
    ...

And when I want to save/load items to/from file, I use Id <--> Index
translation function which translates CommunicateWith array with ID
array.
But that is way too slow to use at normal execution, it is useful only
on file operations.
If I convert these items to objects, there is not much point to use
Alive array (etc.), I'll just remove dead items and add new one only
when needed. But that creates problem with identification, since I
can't use index numbers anymore!
And looping every item to see if it have right Id number (that matches
to CommunicateWith[WhoEverAsk]) is way too slow (like in
Id <--> Index translation function).
Slow because there are many(!) items, and every item should be checked
against every item!

So, any ideas how to implement fast identification between objects?
Other words, how to translate Id to Index without looping?

I'm trying to learn object oriented style and right now it's very
difficult to stretch my brains around it...


Jussi




More information about the User mailing list