Lesson 4
Lesson 4
Overview
The Context and Process
An analysis of software requirements
leads to the creation of various
potential software entities or elements.
As design advances, we refine the
entities and elements, their
responsibilities, their collaborators, and
their relations with external entities and
elements.
Process of identifying software
objects
Design of objects in the context
software construction
Objects are computing or processing software entities, and their interactions
manifest computing and problem-solving. Objects may play different roles.
Some are structural entities, some collectively model software domain
behavior, and some are essentially data structures or data handlers. Domain
elements are typically modeled with objects, compared to computational
processes and services, which can be either static or dynamic entities
depending on situations. Discovery of objects may start with behavioral and
functional decompositions of a system. These decompositions with
conceptualization are the basis for designing procedural and data
abstractions. Conceptualization of entities may benefit the most design of
behavioral polymorphism, but it can also impact design of data
representation, collaborative task completion, and the tradeoff.
For events of the same kind such as button push, we can use an “integrated”
control by “consolidating” responses polymorphically if details of the responses to
different event sources can be abstracted
For some applications, a centralized control is how things work.
A control of elevator operations is a good example. An elevator
control directs elevator movement and must be able to
determine the direction the elevator travels and the floor to
stop. Thus, the control must know the current states of the
floor and elevator buttons. When appropriate, an elevator
control might even manage elevator door operations. Thus, the
role an elevator control plays is global and central. It is much
more often, however, that we design objects that play control
roles in a “local” capacity to control dynamic processes. Here
are a few scenarios of “local” control:
Each unit should have knowledge only about units that are “closely”
related to the current unit
Each unit should only talk to its immediate friends, not strangers
A more colloquial version of the Law is: “Tell, Don’t Ask”
(to “tell” what is needed, not “ask” for more than that). It
is otherwise also known as the “Shy Principle” (to stay
shy of what you might be able to access). In other words,
a collaborating object should offer all needed operations
that use its encapsulated instance data, as opposed to
exporting data for other objects to consume. An object
should be as intelligent as they can be with its own
resources to maximize what they can do
Law of Demeter
To minimize overlapped behaviors, object types should be
behaviorally “orthogonal” or as much different
behaviorally as they can be. For example, if both Order
and Shipping have the access to an address list of
customers, the two types may contain competing
operations. Objects offering similar or competing
operations, if used as collaborators, may potentially
introduce inconsistent behavior in a hosting object
because the overlapping operations of the collaborators
may not be created or updated consistently
Design heuristics