Application Service Pattern


You want to centralize business logic across several business-tier components and services.

Service facades, such as Session Façade or POJO Facades, contain little or no business logic and expose a simple, coarse-grained interface. Business Objects encapsulate cohesive behavior that is specific to a set of related business operations. Applications implement use cases that coordinate multiple Business Objects and services. However, you shouldn't implement use case-coordinating behavior specifically within Business Objects, because it increases coupling and reduces cohesion between these Business Objects. Likewise, you don't want to add this business logic to a service facade, because the business logic potentially gets duplicated among different facades, reducing the reusability and maintainability of common code.


Use an Application Service to centralize and aggregate behavior to provide a uniform service layer.

Application Service provides a central location to implement business logic that encapsulates Business Object and services. Implementing the business logic this way, extrinsically to the Business Object, is a one way to reduce coupling among Business Objects. With an Application Service, you encapsulate this higher-level business logic in a separate component that uses the underlying Business Objects and services.

Application Service is also used to provide a central business logic implementation layer even if you are not using Business Objects in your application. In this scenario, Application Services can include all the procedural business logic required to implement different services in your application and can use Data Access Objects when necessary to deal with persistent data.

What's Next?

Context Object and Application Service are just two additions to the second edition of Core J2EE Patterns. We will cover more patterns in a future article.

We also encourage your involvement in the patterns community. The J2EE Patterns community listserv is a great place to discuss all your patterns-related issues. Alternatively, you can email us at J2EEPatterns-Feedback@Sun.Com, or stop by after our technical session at JavaOne 2003 on Thursday, June 12th and meet us at the JavaOne bookstore for more pattern talk.

Finally, we thank those of you who purchase the book, attend our presentations, contact us via email, participate on the listserv and support the patterns community in general. It is great to hear from each of you and we look forward to a continuing dialogue.

For More Information

§         Amazon

§         Barnes & Noble