Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Design Concern Adapter with static method.

 
Tony Collins
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a concern about my design. I wonder if any of you can help me.
When accessing the DB remotelly I use a instance of RemoteDBAccess, each connection gets a new Object. This basically wraps a DBAdapter instance and adds specific exception handling for remote access.( as opossed to DBLocalAccess).
DBLocalAccess is a Singelton, it wraps a copy of DBAdapter and calls the static method in Data( via DBAdapter) to cache the database, therefore starting the DB, when the user connects.
So when accessing the DB remotelly I have a design problem. I have to start the database from the Server. This involves caching the DB and starting the connection factory. So I call a static method(in data) to cache the DB when I start the Server. This creates the possibility, that a remote connection could try to access the DB before it is cached. That is if I make a programming error. So I need checks in my Database access code, for the event of trying to access a database that hasn't been started.( if i wish to make the class truely portable).
This doesn't seem very Cohesive. Can anyone see my concern. I don't like the design because when accessing the database remotelly there is a condition on it's access( the startDB static function must have been called).
I thought the DB could be cached when the first remote access occurs, but then the Server would not know if a DB path was inncorrect until someone connected.
I'm starting to see the problem with static methods, that add state to a class.
Tony
[ September 09, 2003: Message edited by: Tony Collins ]
[ September 09, 2003: Message edited by: Tony Collins ]
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tony,
I think you're fine: I wouldn't worry about this overmuch. I may not be understanding you correctly, but why not make caching the db part of the process of starting the server? And if that's so, then you can't be faulted for clients who try to access your server befowhen it's midway started
M
 
Tony Collins
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep,
I cache the DB before I start the Server, so I should never get the problem of a remote client accessing a un-cached db. But if I don't consider the fact the db might be un-cached, i'm producing code that relies on previous actions.
I think the design doesn't feel right as a static method can affect the state of the database. And when you start adding checks it becomes un-OO. It's 3am now and I am a little light headed
I hear your a Judoka Max, try the Budokwai in London( home of Brian Jacks and Neil Adams) if you're ever in England.
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tony,
I had a similar issue to be solved, because I wanted to be able to restart the database (reopen = close + open) without the need to disconnect existing clients.
While the database is opening, all other public methods block till the open process is done (but it's very quick, even on 200000 records).
If you have read the discusion I had with Vlad about our multiple-reads-single-write-sycnhronizer, you know that I had nothing special to do to achieve what you are looking for.
If your design doesn't allow it, the solution Max suggests is perfect : a simple "opened" flag that incoming connections check before going on (or block) would do the job.
Best,
Phil.
 
Tony Collins
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah I use a flag but it adds complexity.
BTW Phil you should be submitting soon shouldn't you ?
I am soon but my Data class seems to be a bit of a mess and there doesn't seem to be anything I can do to simplify it.
Tony
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tony Collins:
Yep,
I cache the DB before I start the Server, so I should never get the problem of a remote client accessing a un-cached db. But if I don't consider the fact the db might be un-cached, i'm producing code that relies on previous actions.


Frankly, I don't have a problem with this, from an OO sense. In a very real sense, you can't check all assumptions at all times. I think you're ok to assume that, if the application has started, then the DB is ready to go. Just my opinion.

I think the design doesn't feel right as a static method can affect the state of the database. And when you start adding checks it becomes un-OO. It's 3am now and I am a little light headed
I hear your a Judo Max, try the Budokwai in London( home of Brian Jacks and Neil Adams) if you're ever in England.

That sounds great. one of the first things I do when I get into a new city is look up a local martial arts club. The last time I was lecturing in Amsterdam, I ended up competing @ local no holds barred tourney with something like 3 hours notice.
I love, love, love martial artist, especially the rough and tumble type, like judoka. By and large, they're amazingly generous people who will beat the hell out of you, buy you a beer afterwards, and offer you the run of their house. Really an amazing group of people.
M
 
Tony Collins
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I think static methods can be dangerous though.

Amsterdam what a mentalist city that is.
I think a bit of competition is good for your, it helps you become a more passive considerate person.
I'll probably train at the Budokwai( by Fulham FC) when I finally get work in London.
Tony
[ September 10, 2003: Message edited by: Tony Collins ]
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tony Collins:
Yeah, I think static methods can be dangerous though.
[ September 10, 2003: Message edited by: Tony Collins ]

All method can be dangerous . It's just a matter of how you use them. My point is that static methods aren't inherently dangerous.
All best,
M
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic