In my service, I have a set bean method, that updates the "empty" bean object, by passing a objectID into the set bean method - which then goes to the DAO, since thats the object that should have the SQL or whatever DB code you are using. The bean itself should not know about the database that is being used to get its data so it can do its job of persisting. So, the service calls a getRecord method in the DAO, the DAO sends back a 1 record query to the service. Teh service checks to be sure it has a valid result and then passes the query result to the set bean method in the bean itself.
This seems to make sense - following these good OO practices.
- Service creates objects needed to do the work requested by application
- Service asks the DAO to get a single record, passing in objectID
- DAO returns a single record
- Service ensure the record returned is valid (this could be done in DAO too)
- Service then calls the set bean method in the bean itself, passing in the record to update
In conclusion:
- The DOA does not know about the beans
- The beans do not know about the database
- The service knows about beans and DAOs and Gateways and other services.
No comments:
Post a Comment