Home All Groups Group Topic Archive Search About
Author
25 Apr 2006 11:24 AM
Pavils Jurjans
Hello,

I've come to a question, that seems to be more architecture-oriented, but it
also has some performance issues.

So,

I have the class that is sort of "master" of operation - the applications
would first instantiate this master class, and then all the work will be
done via this single instance. This architacture was chosen, because the
core objects of application are all saved in the database, and to avoid
repeat passing of database connection string when creating the instaces, I'd
rather like to abstract that away and have a master class that knows the
database connection from instantiation, and can create the child objects for
me, internally passing the reference to itself.

Example:

class Parent
{
    private string dbConnStr;
    public Parent(string dbConnStr)
    {
        this.dbConnStr = dbConnStr;
    }
    public string DbConnStr
    {
        get
        {
            return dbConnStr;
        }
    }
    public Child Child()
    {
        return new Child(this);
    }
}
class Child
{
    Parent p;
    public Child(Parent p)
    {
       this.p = p;
    }
    public DoStuff()
    {
        // Do something. If needs DB, use p.DbConnStr
    }
}

Application:
Parent p = new Parent("...");
Child c = p.Child();
c.DoStuff();

The question now I am concerned about is, whether it's better to pass (and
hold in parent's private property) the connection string, or, rather, to
create a connection object in the constructor of Parent and forget the
connection string. It's sort of question - is it Ok to create the
connection, although we don't know if it will be needed. That should have
some performance implications?

Would be happy for some clues/suggestions

Rgds,

Pavils

AddThis Social Bookmark Button