B4J Question [Server] Handler Initialize Sub

Solution
Since the instance of the handler class is not created by you, the programmer, but by B4J-jServer, I would say that Erel meant that you cannot add parameters to the Sub Initialize, which you can do with other classes.

aeric

Expert
Licensed User
Longtime User
Is it a mandatory requirement?
I think "should" doesn't mean "mandatory" but why not just leave it there.
By putting code in the Initialize Sub, do I risk it not to be executed or having other side effects?
I think if you put some code inside, it is expected to be executed. Otherwise it is a bug.
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
I think "should" doesn't mean "mandatory" but why not just leave it there.

I think if you put some code inside, it is expected to be executed. Otherwise it is a bug.

by habit I put my initialization code in the Initialize sub.
I just read that requirement after my project is already written and seemingly running fine.
Being the Handler a class, I expect Initialize to work as usual but that line made me wonder if I was braking some rule that may backfire when least expected.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
by habit I put my initialization code in the Initialize sub.
I just read that requirement after my project is already written and seemingly running fine.
Being the Handler a class, I expect Initialize to work as usual but that line made me wonder if I was braking some rule that may backfire when least expected.
I also expect it is exactly the same as what a normal class is.
I also use the Initialize sub in my web api project template to initialize some objects.
B4X:
Public Sub Initialize
    HRM.Initialize
    HRM.VerboseMode = Main.app.api.VerboseMode
End Sub
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Erel does too if you look at the websocket handler in a new server app, probably more of a what you put there, than don't put stuff there.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I think what Erel wants to bring out is the minimum boilerplate code is to have both Initialize and Handle subs inside this class.
The more important point I can see here is the Handle sub.
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
Since the instance of the handler class is not created by you, the programmer, but by B4J-jServer, I would say that Erel meant that you cannot add parameters to the Sub Initialize, which you can do with other classes.
that sounds good to me: "empty" Initialize has the meaning of "empty parameters list" rather then "no code inside"
 
Upvote 0
Top