locked
Best method of loading data RRS feed

  • Question

  • User1146730029 posted

    Maybe the best way to explain what I want to know if via an example.

    Lets say I have a website for cars. The obvious thing is to create a cars class e.g. clsCars. In this, I have properties that define the make, colour, engine, etc. I instant this class for a new car, or for loading an existing car.

    Now I have a search page where the user can select the make, colour, engine size, etc. from drop down lists (ddl). I need to load these ddls from the database.

    The obvious place to put the code to load the ddls is in the clsCars class. However, I do not want to instance the clsCars class just to load values into the ddls.

    So I make the functions that retrieve the values for the ddls as shared functions.

    My question is, is the correct design? Will I have problems with using shared functions? i.e. what happens when multiple users call the same function, how long does the shared function reside in memory, is there advantages/disadvantages to this?

    (Sorry for the noob question!)

    Monday, March 15, 2010 6:16 AM

Answers

  • User-1618234021 posted

    Hi

    Anything which is shared in the class is loaded when the class is loaded and will remain in the memory unless the class is unloaded. Building shared functions for common utility is ok because even if different users are accessing them, they have the same thing to perform.

    But if you want to build anything which is specific to every user, it should not be static. I am not sure how you are storing the car properties values which these functions are fetching. But your idea to not to use clsCar class to load the values for ddl is quite right.

    I would suggest that you should build a separate utility class for these kind of functions and make them non shared. Whenever you need, instantiate an object and call the functions.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 15, 2010 10:02 AM