java - global object for returning spring singletons -
is there wrong design point of view having global object returns singletons spring context?
i started work @ new place, , daos accessed via global object called daoutils, each dao gets singleton dao bean spring context. if want save purchase order, example, say
daoutils.getpurchaseorderdao().savepurchaseorder(po);
or that.
i've been used injecting daos required each class needs them, , shocked me little. there wrong design point of view, , if can explain why bad idea?
i can see makes unit testing difficult, because there's no way stop code calling actual daoutils class..? guess described problem caused tight coupling?
this bad design pattern since cannot substitute daoutils else e.g. testing purposes.
spring uses dependency injection , that's best way retrieve dao instance.
Comments
Post a Comment