Java Reference
In-Depth Information
Repositories —Manage collections of entities and encapsulate the persistence
framework
Services —Implement responsibilities that can't be assigned to a single class
and encapsulate the domain model
Let's now look at each of these roles.
Entities
Entities are objects that have a distinct business identity that is separate from the
values of their attributes. Two entities are different even if the values of their
attributes are the same and cannot be used interchangeably. Identifying entities is
important because they often correspond to real-world concepts and are central
to the domain model. Examples of entities in this application are PendingOrder ,
Order , and Restaurant .
Value objects
Value objects are objects that are primarily defined by the value of their attributes.
They are often immutable, which means that once they are created they cannot
be updated. Two instances whose attributes have the same values can be used
interchangeably. Examples of value objects in this domain model include
PaymentInformation and Address .
Factories
A Java application creates objects by using the new operator. Sometimes, using the
new operator directly is sufficient, but if you need to instantiate a complex graph
of objects or you need to vary the types of the objects that are created, then you
might need to use a factory. A factory defines methods for creating entities. It
encapsulates the mechanism that instantiates a graph of objects and connects
them together, which simplifies the client code.
Repositories
Repositories manage collections of entities and define methods for finding and
deleting entities. They can also play the role of factories if the factory code is sim-
ple. A repository encapsulates the persistence framework and consists of an inter-
face and an implementation class. The interface defines the methods that can be
called by the repository's client, and the implementation class implements the
interface by calling the persistence framework. Because the persistence frame-
work is encapsulated behind an interface, you can focus on developing the busi-
ness logic without being slowed down or distracted by database issues.
 
 
 
 
Search WWH ::




Custom Search