Hi, all! I was discussing DAOs with a co-worker and he asked whether a DOA could be a static class, ie, containing all static methods like java.lang.Math. So instead of an EJB instantiating a DOA and reusing this instance it would just call static methods. We thought it could done technically but were fuzzy on what the implications might be to app server performance. Any thoughts/comments on this? Thanks,
The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai
Having just static methods in a DAO doesn't allow you to use inheritance and exchanging DAO instances. E.g. if I have an abstract DAO implementation class which my concrete subclasses inherit from. With static methods this wouldnt work (no inheritance on class side in java). The static approach doesnt work if you have different DAO implementations (SybasePersonDAO, OraclePersonDAO). Basically with your approach you loose the benefits of object oriented programming. Peter
You could use a Singleton though if you are confident that all your methods are thread safe.
Joined: Apr 05, 2000
Thanks guys. I was thinking for the static approach that you could handle the loss of inheritance by passing a string indicating the DB (which would be an app variable). But it is probably easier to just go with the normal approach.