This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
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

Pattern decision

 
BJ Grau
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Folks -
I'm trying to decide which patter I am going to use on the client side to switch between local and remote access to the db.
The first one I'm considering is the State pattern. I would have a class called DataAccess which would contain a reference named data to an instance of the interface DataState. DataAccess would present all of the methods from the Data class provided by Sun, and would delegate the work to DataState. DataState has two concrete implementations, DataLocal & DataRemote which behave according to their names. DataAccess.data would point to one or the other depending on the mode.
The other pattern I'm considering is the Factory. I would have a DataFactory class which would return some implementation of the DataAccess interface (not the same DataAccess metioned above), which has two concrete implementations, DataAccessRemote & DataAccessLocal. The DataAccess interface would present all of the methods in Sun's Data class.

I'm leaning towards Factory, I think State is more for situations where you need to change the behavior back and forth. In our case it is a one time deal.
What are everyone's thoughts?
Aside from in the GUI, what patterns has everyone else used?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
 
BJ Grau
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark -
Are you saying I should use Factory, or that you used it, or both? What are your thoughts on State?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I am saying just use it as a Factory.
What are your thoughts on State?

I like states, we have 50 of them in the USA, I actually live in one called California.
OK, enough of my stuff.
State is a specific kind of pattern. You mostly want to only use them when you really need them, like a State Machine. In this kind of assignment you are asking for trouble. My Opinion.
Mark
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Mark. Factory is made for your needs.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic