[ Team LiB ]
Chapter Five. A Model Expressed in
Software
To compromise in implementation without losing the punch of a
MODEL-DRIVEN DESIGN
requires a
reframing of the basics. Connecting model and implementation has to be done at the detail level.
This chapter focuses on those individual model elements, getting them in shape to support the
activities in later chapters.
This discussion will start with the issues of designing and streamlining associations.
Associations
between objects are simple to conceive and to draw, but implementing them is a potential
quagmire. Associations illustrate how crucial detailed implementation decisions are to the viability
of a
MODEL-DRIVEN DESIGN
.
Turning to the objects themselves, but continuing to scrutinize the relationship
between detailed
model choices and implementation concerns, we'll focus on making distinctions among the three
patterns of model elements that express the model:
ENTITIES
,
VALUE OBJECTS
, and
SERVICES
.
Defining objects that capture concepts of the domain seems very intuitive on the surface, but
serious challenges are lurking in the shades of meaning. Certain distinctions have emerged that
clarify the meaning of model elements and tie into a body of design
practices for carving out
specific kinds of objects.
Does an object represent something with continuity and identity—something that is tracked
through different states or even across different implementations? Or is it an attribute that
describes the state of something else? This is the basic distinction between an
ENTITY
and a
VALUE
OBJECT
. Defining objects that clearly follow one pattern or the other makes the objects less
ambiguous and lays out the path toward specific choices for robust design.
Then there are those aspects of the domain that are more clearly expressed as actions or
operations, rather than as objects. Although it is a slight departure from
object-oriented modeling
tradition, it is often best to express these as
SERVICES
, rather than forcing responsibility for an
operation onto some
ENTITY
or
VALUE OBJECT
. A
SERVICE
is something that is done for a client on
request. In the technical
layers of the software, there are many
SERVICES
. They emerge in the
domain also, when some activity is modeled that corresponds to something the software must do,
but does not correspond with state.
There are inevitable situations in which the purity of the object model must be compromised, such
as for storage in a relational database. This chapter will lay out some guidelines for staying on
course when you are forced to deal with these messy realities.
Finally,
a discussion of
MODULES
will drive home the point that every design decision should be
motivated by some insight into the domain. The ideas of high cohesion and low coupling, often
thought of as technical metrics, can be applied to the concepts themselves. In a
MODEL-DRIVEN
DESIGN
,
MODULES
are part of the model, and they should reflect concepts in the domain.
This chapter brings together all of these building blocks, which embody the model in software.
These
ideas are conventional, and the modeling and design biases that follow from them have
been written about before. But framing them in this context will help developers create detailed
components that will serve the priorities of domaindriven design when tackling the larger model
and design issues. Also, a sense of the basic principles will help developers stay on course through
the inevitable compromises.