What is the best practice?



Hi

I have many classes that use database connections to fetch data and manipulate on it. I also have database abstraction class that is handling all the database queries and so forth.

Usually all my classes take instantiated database object as the first parameter to constructor so they know what database to use:

public function __constructor(Database $db, $var1, $var2){

if($db->is_connected()){
// construct class
} else {
throw new Exception('Bla bla bla');
}
}

then in the script i do:

try{
$db = DB::create_DB($DB_settings);
$u = new theOtherClass($db, $var1, $var2);
} catch (...)

It works great if the class uses only one database connection. I establish connection pass the object to "theOtherClass" and I'm happy :)

Now I'm designing class that will be aggregating at least 5 other classes that might use different databases.

I don't want to create 5 objects and then pass them to this class' constructor. So I'm looking for better way to do it.
Any ideas?

Ralph

PS: I was thinking of passing array with all the settings to the constructor and then creating objects internally based on info in an array. But don't like the idea so much.
.



Relevant Pages

  • aggregation class ideas?
    ... I have many classes that use database connections to fetch data and manipulate on it. ... I also have database abstraction class that is handling all the database queries and so forth. ... I don't want to create 5 objects and then pass them to this class' constructor. ... I was thinking of passing array with all the settings to the constructor and then creating objects internally based on info in an array. ...
    (comp.lang.php)
  • Re: aggregation class ideas?
    ... I have many classes that use database connections to fetch data and manipulate on it. ... I also have database abstraction class that is handling all the database queries and so forth. ... I don't want to create 5 objects and then pass them to this class' constructor. ... I was thinking of passing array with all the settings to the constructor and then creating objects internally based on info in an array. ...
    (comp.lang.php)
  • Re: In FrontPage 2003 what is a thicket?
    ... | and database connections. ... | as good), the error, "Database Results Wizard Error ... | the file was part of a thicket and could not be changed. ...
    (microsoft.public.frontpage.extensions.windowsnt)
  • Re: aggregation class ideas?
    ... I also have database abstraction class that is ... database connections in your application, ... situation, the active record, table gateway, or data mapper patterns ... mapper pattern even in simple situations, ...
    (comp.lang.php)
  • RE: Memory Leak in C# Windows Service
    ... With your database connections and datareaders you want to make sure ... > jobs and starting to "sleep". ... Actually the service is working fine except memory leak, ...
    (microsoft.public.dotnet.general)