Java Reference
In-Depth Information
a model object, model fields, and pages. In general, object level is best but
may not be coarse enough.
Tips for granularity
When we're deciding how to partition a set of commands, we must consider a
number of clues. We should start by looking at the entities and attributes in
our model. For an object-oriented application, this exercise is relatively simple.
If the model is data driven, it may be more complex, especially if the database
tables are not normalized to interesting entities and relationships. Transaction
and messaging models may be similarly difficult.
After identifying the entities and attributes, we should look for groupings
that appear to be natural, intuitive, and logical. We should also examine usage
in our current interface and determine what entities are being used. What are
the usage patterns? Are there natural groupings? If we have any use cases avail-
able, they may also suggest groupings. Who are the users of the system? Will
our command layer be exposed as an API ? If so, how are interfaces in our
domain usually organized? Finally, based on domain knowledge, we should
anticipate how the commands are likely to be used.
The answers to all of these questions can be used to partition the com-
mand set. The first iteration is not necessarily set in stone. In the early stages
of development, refactoring is easy. Several rules of thumb are helpful:
If logical groupings and usage patterns conflict, choose the logical
grouping. Also, look harder because sometimes entities are related in
unusual ways.
If a group of commands are used both individually and together, pack-
age them individually.
It is okay to use a command that returns slightly more than you need. If
you find yourself using a small fraction of the fields in a command on a
regular basis, then it's time to refactor.
If the same combination of logically similar commands is used fre-
quently, consider refactoring to combine the group.
Read good code. Find a mentor whom you trust, and read that person's
code. Even if the code does not explicitly use the command pattern,
many of the concepts of good object-oriented design translate.
Search WWH ::

Custom Search