concept business logic in category ejb

appears as: business logic, The business logic, business logic
EJB 3 in Action, Second Edition

This is an excerpt from Manning's book EJB 3 in Action, Second Edition.

Figure 1.3 shows domain-driven architecture. The term domain-driven design may be relatively new but the concept is not (see Domain-Driven Design: Tackling Complexity in the Heart of Software, by Eric Evans [Addison-Wesley Professional, 2003]). DDD emphasizes that domain objects should contain business logic and shouldn’t just be dumb replicas of database records. Domain objects can be implemented as entities in JPA. With DDD, a Catalog object in a trading application might, in addition to having all the data of an entry in the catalog table in the database, know not to return catalog entries that aren’t in stock. Being POJOs, JPA entities support OO features, such as inheritance and polymorphism. It’s easy to implement a persistence object model with the JPA and to add business logic to your entities. Now, DDD still utilizes a service layer or application layer (see Patterns of Enterprise Application Architecture, by Martin Fowler [Addison-Wesley Professional, 2002]). The application layer is similar to the business logic layer of the traditional four-tier architecture but much thinner. EJB works well as the service-layer component model. Whether you use the traditional four-tier architecture or a layered architecture with DDD, you can use entities to model domain objects, including modeling state and behavior. We’ll discuss domain modeling with JPA entities in chapter 7.

Figure 2.2. The ActionBazaar scenario implemented using EJB 3. From the EJB 3 perspective, the presentation layer is an amorphous blob that generates business logic–tier requests (in this case it’s implemented using JSF). The business logic–tier components match up with the distinct processes in the scenario—putting a bid on an item and ordering the item won. The business logic–tier components use JPA entities to persist the application state into the database via persistence-layer DAO components.

At the heart of any enterprise application is its business logic. In an ideal world, application developers should mainly be concerned with implementing business logic, while concerns like presentation, persistence, and integration should largely be window dressing. From this perspective, session beans are the most important part of the EJB technology because their purpose in life is to model high-level business processes.

If you think of a business system as a horse-drawn chariot carrying the Greco-Roman champion to battle, session beans are the driver. Session beans utilize data and system resources (the chariot and horses) to implement the goals of the user (the champion) using business logic (the skills and judgment of the driver). For this and other reasons, sessions beans, particularly stateless session beans, have been popular, even despite the problems of EJB 2. EJB 3 makes this vital bean type much easier to use and adds some important functionality.