Java Reference
In-Depth Information
reducing network traffic and memory requirements for our application. i BATIS
can help achieve these goals using features that allow querying for specific ranges
of data.
The business logic layer
The business logic layer of the application describes the coarse-grained services
that the application provides. For this reason they are sometimes called service
classes. At a high level, anyone should be able to look at the classes and methods
in the business logic layer and understand what the system does. For example, in a
banking application, the business logic layer might have a class called TellerSer-
vice , with methods like openAccount() , deposit() , withdrawal() , and getBal-
ance() . These are very large functions that involve complex interactions with
databases and possibly other systems. They are much too heavy to place into a
domain class, as the code would quickly become incohesive, coupled, and gener-
ally unmanageable. The solution is to separate the coarse-grained business func-
tions from their related business object model. This separation of object model
classes from logic classes is sometimes called noun-verb separation .
Object-oriented purists might claim that this design is less object oriented than
having such methods directly on the related domain class. Regardless of what is
more or less object oriented , it is a better design choice to separate these concerns.
The primary reason is that business functions are often very complex. They usu-
ally involve more than one class and deal with a number of infrastructural compo-
nents, including databases, message queues, and other systems. Furthermore,
there are often a number of domain classes involved in a business function, which
would make it hard to decide which class the method should belong to. It is for
these reasons that coarse-grained business functions are best implemented as sep-
arate methods on a class that is part of the business logic layer.
Don't be afraid to put finer-grained business logic directly on related domain
classes. The coarse-grained service methods in the business logic layer are free to
call the finer-grained pure logic methods built into domain classes.
In our layered architecture, the business logic layer is the consumer of the per-
sistence layer services. It makes calls to the persistence layer to fetch and change
data. The business logic layer also makes an excellent place to demarcate transac-
tions, because it defines the coarse-grained business functions that can be con-
sumed by a number of different user interfaces or possibly other interfaces, such
as a web service. There are other schools of thought regarding transaction demar-
cation, but we'll discuss the topic more in chapter 8.
Search WWH ::

Custom Search