stated class, stateless class, 两种类别，代表了一种思路
Stateless or Stateful?
Service objects will usually be stateless. Stateless service layers are highly scalable: They pose no replication
issues and there is no need to allocate additional resources for every client. (Remember that one of
the key motivations of a middle tier is to share resources between multiple clients.) It is also much easier
for stateless service layers to support remote clients, if necessary.
The traditional stateless service objects in J2EE applications are stateless session beans (SLSBs). I’ll use
SLSBs as a starting point for discussion because they illustrate many of the basic concepts of stateless
service objects, which predate EJB.
A stateless service layer is one concession of object orientation that I find not too painful. Stateless service
objects are semi-objects. Although they cannot expose state to callers, they can hold internal state
and they can fully participate in inheritance relationships. If they are local, rather than remote, they can
use true objects as parameters and return values.
There are two main potential models for stateful service layers in J2EE: stateful session beans (SFSBs) and
web tier session objects. If we don’t use stateful session beans, session data is usually held in Servlet API
HttpSession objects. Holding session data in the web tier is usually more scalable than holding it in the
EJB tier. (See Chapter 10 of Expert One-on-One J2EE Design and Development for detailed discussion of
state replication issues.) “Thick” clients such as Swing applications will normally hold their own state.
Because stateless service layers have proven their value in numerous technologies, including both J2EE
and Microsoft platforms, we’ll focus on them in this book.
If possible, design applications to use a stateless service layer. Hold state in the web
tier, rather than in the business logic tier, if possible.