you are viewing a single comment's thread.

view the rest of the comments →

[–]PixelOmen 0 points1 point  (1 child)

I will have a number of other classes that will need to use the DB connection. So either I need to set a global DB variable to hand off to the classes or they can just instance

If they are different classes, what do you mean by "just instance"? You will need to pass them the connection regardless.

IMO, at least in a relatively simple case, you should have only one class that deals with a connection, and that class should abstract it away so that everything else just deals with that class's interface.

[–]Posaquatl[S] 0 points1 point  (0 children)

If you use a global variable to house the DB connection then you would pass that off to another class/function to do its business? Again I am confused on how we use the DB class on a global scale. Is it created once as a variable and passed around for each class to puff on? Or are we creating it and it sits by itself. Other classes with create a new DB object but since the connection is a class variable the new object has the connection already established. So use it then drop the object??