Java Reference
In-Depth Information
Transaction
Scripts
(Session
Beans)
Legend:
Behavior
State
Data
Objects
Figure 2.2 The structure of a procedural design: large transaction script classes
and many small data objects
Nevertheless, you should not be ashamed to use a procedural design when it is
appropriate. In chapter 9 you will learn when it does make sense and see some
ways to improve a procedural design.
2.2.2
Using an object-oriented design
The simplicity of the procedural approach can be quite seductive. You can just
write code without having to carefully consider how to organize the classes. The
problem is that if your business logic becomes complex, then you can end up with
code that's a nightmare to maintain. Consequently, unless you are writing an
extremely simple application you should resist the temptation to write procedural
code and instead develop an object-oriented design.
In an object-oriented design, the business logic consists of an object model,
which is a network of relatively small classes. These classes typically correspond
directly to concepts from the problem domain. For example, in the money transfer
example in section 1.2 the POJO version consists of classes such as TransferService ,
Account , OverdraftPolicy , and BankingTransaction , which correspond to con-
cepts from the banking domain. As figure 2.3 shows, in such a design some classes
have only either state or behavior but many contain both, which is the hallmark of
a well-designed class.
As we saw in chapter 1, an object-oriented design has many benefits, including
improved maintainability and extensibility. You can implement a simple object
model using EJB 2 entity beans, but to enjoy most of the benefits you must use
POJO s and a lightweight persistence framework such as Hibernate and JDO . POJO s
enable you to develop a rich domain model, which makes use of such features as
inheritance and loopback calls. A lightweight persistence framework enables you
to easily map the domain model to the database.
 
 
 
 
Search WWH ::




Custom Search