• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about Data class and DAO (URLyBird)

 
Daniel Breitner
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,

what do you think about the following design:

I have designed my Data class to be initialized with a DAO.

The data class holds this dao static and forwards every call to this dao.


Is this flexible enough (dao may be substituted by another data source specific dao) or do you think I should bring in a DaoFactory ?


with kind regards


daniel
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Daniel!

Well, I see the Data class itself as a DAO. What are the methods that your DAO has?

I myself created a DAOFactory, but today I see that it isn't really necessary. If it is a singleton, all your Data class needs to have is a getInstance(String) method, called when the application starts. The argument is the database location, provided by the user when the application starts.

I'd say that your Data class has to be responsible for dealing with data and locking, being a facade or doing all this. Just take care and do not over complicate things... maybe your design is getting a little complicated...
 
Daniel Breitner
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I see the Data class itself as a DAO. What are the methods that your DAO has?


My concept was to leave the locking of records in the Data class and for everything else forward it to the DAO which then does all the data source specific locking, reading a.s.o.

 
Olu Shiyan
Ranch Hand
Posts: 57
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Roberto, Hmmm, I was just asking myself that question as well i.e. 'Do I really need a DAOFactory?' and I'm happy that someone else shares my opinion on this.


 
Seetharaman Iyer
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Even myself did the same way. My DAO is dedicated for I/O operations only (record cache, read/load and write). And Data class is for Locking mechanism (no I/O operations at all), for I/O operations, Data class will simply forward the request to DAO (it's singleton - assume this is like JDBC engine)

My concept is Local client will directly access DAO (no need to go through/access Data class) for I/O related tasks
and network client will access Data class for both locking and I/O related tasks.

The only thing left for me on this whole development is how to avoid code redundancy for I/O related operations. I meant both local client & network client has to read/search/create/update/delete. I just planned to put all these 5 tasks in either DAO itself or Common Operation Gateway (a class) - so in either case, except for locking mechanism (lock/unlock) Data class will behave as Dummy for I/O related tasks for network client.
 
Olu Shiyan
Ranch Hand
Posts: 57
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Seetharama,


Even myself did the same way. My DAO is dedicated for ...


I think you misunderstood my post. What I meant to say was that I don't think I'll use a Factory approach (i.e. DAOFactory) for my Data access layer. For now, I've simply chosen to implement my Data class as a Singleton with getInstance() methods for retrieving a reference to the Singleton (i.e. the Data object) and all methods marked synchronized.



Cheers
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic