dimanche 28 juin 2015

Calling one DAO from another DAOFactory

Currently, my application architecture flows like this:

View → Presenter → Some asynchronous executor → DAOFactory → DAO (interface) → DAO (Impl)

For the time being, this kind of architecture works; mainly because I've only been needing one kind of DAO at the moment. But as the requirement grows, I'd need to expand to multiple DAOs, each with their own implementation on how to get the data.

Here's an illustration to my case:

enter image description here

The main headache comes from FooCloudDao which loads data from an API. This API needs some kind of authentication method - a string token that was stored during login (say, a Session object - yes, this too has its own DAO).

It's tempting to just pass a Session instance through FooDaoFactory, just in case there's no connection, but it seems hackish and counter-intuitive. The next thing I could imagine is to access SessionDAOFactory from within FooDaoFactory to gain instance of a Session (and then pass that when I need a FooCloudDAO instance).

But as I said, I'm not sure whether or not I could do a thing like this - well, may be I could, but will it be ethical?

Aucun commentaire:

Enregistrer un commentaire