Python Book
Python Book
1
Introduction
None of this is new. Over thirty years ago, the U.S. Department of Defense
warned of a “software crisis” and predicted that to meet the burgeoning
need for software by the end of the century, everyone in the country would
have to become a programmer. In many ways this prediction has come
true, as anyone who has checked on the progress of a flight or made a
stock trade using the Internet can tell you. Nowadays, we all write our own
1 Robert Block began his book The Politics of Projects[1] in a similar manner.
1
01-Introduction.fm Page 2 Wednesday, April 17, 2002 4:33 PM
2 INTRODUCTION
The manner in which each higher layer of abstraction reached the market fol-
lows a pattern. The typical response to the introduction of the next layer of
abstraction goes something like this: “Formula translation is a neat trick, but
even if you can demonstrate it with an example, it couldn’t possibly work on a
problem as complex and intricate as mine.”
As the tools became more useful and their value became more obvious, a whole
new set of hurdles presented themselves as technical folk tried to acquire the
wherewithal to purchase the tools. Now managers wanted to know what would
happen if they came to rely on these new tools. How many vendors are there?
Are other people doing this? Why should we take the risk in being first? What
happens if the compiler builder runs out of business? Are we becoming too
dependent on a single vendor? Are there standards? Is there interchange?
Executable UML and the tooling necessary to compile and debug an executable
UML model are only now passing from this stage, so expect some resistance
today and much better tools tomorrow.
But over time the new layers of abstraction became formalized, and tools
such as assemblers, preprocessors, and compilers were constructed to
support the concepts. This has the effect of hiding the details of the lower
layers so that only a few experts (compiler writers, for example) need con-
cern themselves with the details of how that layer works. In turn, this
raises concerns about the loss of control induced by, for example, elimi-
nating the GOTO statement or writing in a high-level language at a dis-
tance from the “real machine.” Indeed, sometimes the next level of
abstraction has been too big a reach for the profession as a whole, of inter-
est to academics and purists, and the concepts did not take a large enough
mindshare to survive. (ALGOL-68 springs to mind. So does Eiffel, but it has
too many living supporters to be a safe choice of example.)
01-Introduction.fm Page 4 Wednesday, April 17, 2002 4:33 PM
4 INTRODUCTION
Object methods have a complex history because they derive from two very dif-
ferent sources.
Be that as it may, the search was on for a higher level of abstraction than the
programming language, even though some claimed that common third-gener-
ation programming languages such as Smalltalk had already raised the level of
abstraction far enough.
The other source was more centered in analysis. These approaches focused on
modeling the concepts in the problem, but in an object-oriented way. Classes
could be viewed as combinations of data, state, and behavior at a conceptual
level only. In addition to the model, reorganization of “analysis” classes into
“design” classes, and re-allocation of functionality were expected. There was no
need to model the specific features used from a programming language
because the programmer was to fill in these details. Perhaps the purest propo-
nents of this point of view were Shlaer and Mellor. They asserted classes with
attributes clearly visible on the class icon seemingly violating encapsulation,
with the full expectation that object-oriented programming schemes would
select an appropriate private data structure with the necessary operations.
These two sources met in the middle to yield a plethora of methods, each with
its own notation (at least 30 published), each trying to some extent to meet the
needs of both camps. Thus began the Method Wars, though Notation Wars
might be more accurate.
UML is the product of the Method Wars. It uses notations and ideas from many
of the methods extant in the early nineties, sometimes at different levels of
abstraction and detail.
01-Introduction.fm Page 5 Wednesday, April 17, 2002 4:33 PM
EXECUTABLE UML 5
The first model identifies, classifies, and abstracts the real or hypothetical
world under study, and it organizes the information into a formal struc-
ture. Similar “things,” or objects, in the subject matter under study are
identified and abstracted as classes; characteristics of these objects are
abstracted as attributes; and reliable associations between the objects are
abstracted as relationships.
01-Introduction.fm Page 6 Wednesday, April 17, 2002 4:33 PM
6 INTRODUCTION
classes
the world attributes
data UML class diagram
is full of things associations
constraints
states
things have events
control UML statechart diagram
lifecycles transitions
procedures
things do things at
algorithm actions action language
each stage
We express this first model using a UML class diagram. The abstraction
process requires that each object be subject to and conform to the well-
defined and explicitly stated rules or policies of the subject matter under
study, that attributes be abstractions of characteristics of things in the
subject matter under study, and that relationships similarly model associ-
ations in the subject matter.
Next, the objects (the instances of the classes) may have lifecycles (behav-
iors over time) that are abstracted as state machines. These state
machines are defined for classes, and expressed using a UML statechart
diagram. The abstraction process requires that each object be subject to
and conform to the well-defined and explicitly stated rules or policies of
the world under study, so each object is known to exhibit the same pattern
of behavior.
The behavior of the system is driven by objects moving from one stage in
their lifecycles to another in response to events. When an object changes
01-Introduction.fm Page 7 Wednesday, April 17, 2002 4:33 PM
Executable UML is a single language in the UML family, designed for a single
purpose: to define the semantics of subject matters precisely. Executable
UML is a particular usage, or profile, the formal manner in which we specify
a set of rules for how particular elements in UML fit together for a particular
purpose.
state, something must happen to make this new state be so. Each state
machine has a set of procedures, one of which is executed when the object
changes state, thus establishing the new state.
Each procedure comprises a set of actions. Actions carry out the funda-
mental computation in the system, and each action is a primitive unit of
computation, such as a data access, a selection, or a loop. The UML only
recently defined a semantics for actions, and it currently has no standard
notation or syntax, though several (near-)conforming languages are avail-
able.
These three models—the class model, the state machines for the classes,
and the states’ procedures—form a complete definition of the subject
matter under study. Figure 1.1 describes the concepts in an Executable
UML model.
In this book we will informally make use of other UML diagrams, such as
use case and collaboration diagrams, that support the construction of exe-
cutable UML models or can be derived from them. We encourage using
any modeling technique, UML-based or otherwise, that helps build the
system.
8 INTRODUCTION
Executable UML isn’t just a good idea, it’s real. There are several Executable
UML vendors, and the models in this book have been executed to ensure
! they are correct. The case study models and the toolset are downloadable.
For UML to be executable, we must have rules that define the dynamic
semantics of the specification. Dynamically, each object is thought of as
executing concurrently, asynchronously with respect to all others. Each
object may be executing a procedure or waiting for something to happen
to cause it to execute. Sequence is defined for each object separately; there
is no global time and any required synchronization between objects must
be modeled explicitly.
Executable UML helps us work out how we want to think about a solution:
the terms we need to define, the assumptions we make in selecting those
terms, and the consistency of our definitions and assumptions. In addi-
tion, executable UML models are separate from any implementation, yet
can readily be executed to test for completeness and correctness.
Most important of all, together with a model compiler, they are execut-
able.
01-Introduction.fm Page 9 Wednesday, April 17, 2002 4:33 PM
MODEL COMPILERS 9
There are many possible executable UML model compilers for different
system architectures. Each architecture makes its own decisions about the
organization of hardware and software, including even the programming
language. Each model compiler can compile any executable UML model
into an implementation.
01-Introduction.fm Page 10 Wednesday, April 17, 2002 4:33 PM
10 INTRODUCTION
The notion of so many different model compilers for such different software
! architecture designs is a far cry from the one-size-fits-all visual modeling
tools of the past.
MODEL-DRIVEN ARCHITECTURE 11
financial transactions would prefer one with transaction safety and roll-
back.
These choices will affect performance of the model compiler. One particu-
larly performance-sensitive feature is static allocation to tasks and proces-
sors. Allocating two classes that communicate heavily with different
processors could cause significant degradation of network performance
and of your system. If this is so, of course, it’s a simple matter to re-allo-
cate the elements of the model and recompile. This is why executable
UML is so powerful—by separating the model of the subject matter from
its software structure, the two aspects can be changed independently,
making it easier to modify one without adversely affecting the other. This
extends the Java notion of the “write once, run anywhere” concept; as we
raise the level of abstraction, we also make our programs more portable. It
also enables a number of interesting possibilities for hardware-software
co-design.
12 INTRODUCTION
At the time of writing, MDA is still being defined. However, some variation
of the concepts of executable UML will, in our opinion, be required to sup-
port MDA. We offer our view on executable UML concepts here. Describ-
ing and defining MDA is another project and another book.
1.6 References
[1] Block, Robert: The Politics of Projects. Yourdon Press, New York, NY,
1983.
[2] Kabira Technologies URL: www.kabira.com
[3] Project Technology, Inc. URL: www.projtech.com