Connection object as an instance or local variable?
From: relaxedrob_at_optushome.com.au (relaxedrob_at_optusnet.com.au)
Date: 10/07/04
- Next message: Rob Seegel: "Possible variation on "Invalid name pattern" exception"
- Previous message: Thomas Schodt: "Re: A good IDE??"
- Next in thread: Dieter Bender: "Re: Connection object as an instance or local variable?"
- Reply: Dieter Bender: "Re: Connection object as an instance or local variable?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 6 Oct 2004 20:20:04 -0700
Hi All!
I have a 'data manager class' that has a bunch of methods a bit like
this:
public Hotel [] getHotels()
{
// Open a connection to the database.
// Execute sql command.
// Format results as a Hotel array.
// Close database connection.
// Return array.
}
Is it a better design to have the connection object as an instance
variable or leave it as a local variable in this case?
As an instance variable:
- may put less load on the database.
- allow me to keep a 'one client, one connection' paradigm.
- but I may need to synchronize access to the connection.
- I would have to expose a 'close()' method which doesn't really fit
the contract of a data manager (which should hide the fact that it may
or may not use a database) or:
- I put the connection closing code in a finalize() method or;
- use a thread run method somehow?
As a local variable:
- 'heavy' usage on the database.
- lots of over head for my application opening and closing all the
time..
Any advice would be most appreciated!
Rob
:)
- Next message: Rob Seegel: "Possible variation on "Invalid name pattern" exception"
- Previous message: Thomas Schodt: "Re: A good IDE??"
- Next in thread: Dieter Bender: "Re: Connection object as an instance or local variable?"
- Reply: Dieter Bender: "Re: Connection object as an instance or local variable?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|