mimi mang wrote:ServiceLocator is still useful for those POJO objects that are not managed objects for example Business Objects, DAO/EAOs etc. Even in web tier, I don't prefer to use Dependency Injection with annotation. because it can't logically seperate ejbs from web tier managed beans especially when you need 2 kind of presentation tier such as web client and swing client.
The problem is it really make the diagram messy. not sure if we need draw every dependency line to it...
I agree, this pattern could be still useful in some special cases, but DI is essential new feature in EJB3 and behind the scene it's doing much more than just lookup (think about @PersistentContext) like CMT and CMP, therefore I always would recommend using it. About the clear separation of concerns, you can still wrap the injection in more decoupled way if you prefer, but let's remember that annotations came in JEE5 to solve some very typical issue - the bunch of boilerplate code. I would say ServiceLocator is one good example for that and when you see the new DI (JSR-299) is even further improved in JEE6, you'll see that new style of design.
About the pattern existence in class diagram, yes it could become more complex, but it might me necessary since you also would include it in sequence diagram and component diagram to show how exactly your design provide good maintainability and extensibility
Oracle Certified Master, Java EE 6 Enterprise Architect
TOGAF 8 Certified
Sun Certified Enterprise Architect for JEE 5
Sun Certified Business Component Developer for JEE 5
Sun Certified Web Component Developer for J2EE 1.4
Sun Certified Java Programmer for Java 5
LPI Linux Certified Professional
Certified Scrum Master