Encapsulation

wl

Well-Known Member
Licensed User
Longtime User
Hi,


I am reading from a TCP socket but instead of using the prefixed mode I'm relying on my own message structure: I have implemented this as a method in a code module which gets a byte as parameter and adds it to a stringbuilder etc.

Between the calls to this method I need to keep state (am I reading the header info similar as the prefix bytes, or reading the message etc). Currently the state (and other variables) is stored as a variable in the global_process.

However, what if the same code gets executed multiple times (different threads) ? The only solution seems to keep the state variables in the threading code.

In Object-Oriented code I would have created a class that kept the state variables as private variables. Since OO has not yet been implemented in B4A, what would be the best approach ?

I was thing of a map with all variables I need to keep state (a map can also contain a list and other objects ?) so that at least I only need to store 1 variable outside the code module ?

Any other suggestions ?

Thanks
 

wl

Well-Known Member
Licensed User
Longtime User
To answer myself: it seems type structures can contain objects. Unfortunately, these can not be passed as params to functions which makes them unusable for this purpose...
 
Upvote 0

wl

Well-Known Member
Licensed User
Longtime User
But still: if someone else has another idea of how implement some method of encapsulation in B4A ?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…