Is it OK to use a local variable and call this in every function or... ?

0 votes

Which is better?

1. Only once,  initial a GLOBAL variable, e.g.  'userService' with the BuildUserService(). And use that GLOBAL variable in every function where you need to call a UserService.


2. In each and every function where you need to call a UserService, initial a LOCAL variable, e.g.  'userService' with the BuildUserService(). And use that LOCAL variable to call the UserService.

NOTE: Is it OK to use example 2 and repeatedly initialize the UserService? 

e.g. UserService userService = sp.BuildUserService();

asked Jul 11, 2014 in App42 Cloud API-BaaS by huffman (17 points)
edited Jul 11, 2014 by huffman

1 Answer

0 votes

If you have requirement where you have to pass meta information like AddJSONDoc/orderBy etc on method call, it is advisable to use different userService reference for each call. However if your method calls do not use these meta info, you can have global reference for the same. Since App42 APIs provides meta info to be passed along with the call to over load its behavior, it is better to use local reference wherever needed to avoid any confusion.

Let me know if it helps
answered Jul 11, 2014 by ajay123 (899 points)

Then how do I know which calls DO pass meta info and which calls DON'T pass meta?
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on