Chapter 1 Oomd
Chapter 1 Oomd
Chapter-1 - OOMD
Introduction
Object-oriented modeling and design is a way of thinking about problems using models or-
gafized around real-world concepts. The fundamental construct is the object, which com-
bines both data structure and behavior. Object-oriented rnodels are useful for understanding
problems, communicating with application experts, modeling enterprises, preparing docu-
mentation, and designing programs and databases. This book presents an object-oriented no-
tation and process that extends from analysis through design to implementation. The same
notation applies at all stages ofthe process as development proceeds.
Chapter 1 / lntroduction
variable name
aCredit
aDebit
anAccount
aSavingsAccount
address
10000007
13537163
56826358
a symbol table
45205128 A
binary tree
ffi
ry--
a monitor
bicycle
Mike's bicycle Brian's bicycle a white rook
Classi,fication means that objects with the same data structure (attrihutes) and behavior
(operations) are grouped into a class. Paragraph, Monitor, and ChessPiece are examples of
classes. Aclass is an abstraction that describes properties important to an application and ig-
nores the rest. Any choice of classes is arbitrary and depends on the application.
Each class describes a possibly infinite set of individual objects. Each object is said to
be an instance of its class. An object has its own value for each attribute but shares the at-
tribute names and operations with other instances of the class. Figure 1.2 shows two classes
and some of their respective instances. An object contains an implicit reference to its own
class; it "knows what kind of thing it is."
Inheritance is the sharing of attributes and operations (features) among classes based
on a hierarchical relationship. A superclass has general information that subclasses reflne
and elaborate. Each subclass incorporates, or inherits, all the features of its superclass and
adds its own unique features. Subclasses need not repeat the features ofthe superclass. For
example, ScrollingWindow and FixedWindow are subclasses of Wndow. Both subclasses in-
herit the features of Wndow, such as a visible region on the screen. ScrollingWindow adds a
scroll bar and an offset. The ability to factor out common feafures of several classes into a
superclass can greatly reduce repetition within designs and programs and is one of the main
advantages of OO technology.
Polymorphisrn means that the same operation may behave differently for different
classes. Tlte move operation, for example, behaves differently for a pawn than for the queen
in a chess gane. An operation is a procedure or transformation that an object performs or is
subject to. Rightlustify, display, and move are examples of operations. An implementation of
an operation by a specific class is calledamethod. Because an OO operator is polymorphic,
it may have more than one method implementing it, each for a different class of object.
In the real world, an operation is simply an absffaction of analogous behavior across dif-
ferent kinds of objects. Each object "knows how" to perform its own operations. In an OO
programming language, however, the language automatically selects the correct method to
Bicycle objects
L3 Bicycle class
#).@ L__:t'
Attributes
frame size
wheel size
number of gears
+ abstract
#\,@ into material
Operations
trJ shift
move
#)'@ repair
I
)| + abstract
fillcolor
Operations
into
draw
erase
move
Figure 1.2 Objects and classes. Each class describes a possibly infinite
set of individual objects.
implement an operation based on the name of the operation and the class of the object being
operated on. The user of an operation need not be aware.of how many methods exist to im-
plement a given polymorphic operation. Developers can add new classes without changing
existing code, as long as they provide methods for each applicable operation.
Chapter 1 / lntroduction
7.2.2 OO ilIethodologg
We present a process for OO development and a graphical notation for representing OO con-
cepts. The process consists of building a model of an application and then adding details to
it during design. The same seamless notation is used from analysis to design to implemen-
tation, so that information added in one stage of development need not be lost or franslated
for the next stage.The methodology has the following stages.
I System conception. Software development begins with business analysts or users con-
ceiving an application and formulating tentative requirements.
I Analysis. The analyst scrutinizes and rigorously restates the requirements from system
conception by constructing models. The analyst must work with the requestor to under-
stand the problem, because problem statements are rarely complete or correct. The anal-
ysis model is a concise, precise abstraction of wh&t the desired system must do,not how
it will be done. The analysis model should not contain implementation decisions. For
example, a Window class in a workstation windowing system would be described in
terms of its visible attributes and operations.
The analysis model has two parts: the ilom.ain nndel, a desciption of the real-world
objects reflected within the system; andtheapplication model, a description of the parts
of the application system itself that are visible to the user. For example, domain objects
for a stockbroker application might include stock, bond, trade, and commission. Appli-
cation objects might control the execution of ffades and presentthe results. Application
experts who are not programmers can understand and criticize a good model.
I System design. The development team devise a high-level strategy-the system archi-
tecture-for solving the application problem. They also establish policies that will serve
as a default for the subsequent, more detailed portions of design. The system designer
must decide what performance characteristics to optimize, choose a strategy of attack-
ing the problem, and make tentative resource allocations. For example, the system de-
signer might decide that changes to the workstation screen must be fast and smooth,
even when windows are moved or erased, and choose an appropriate communications
protocol and memory buffering strategy.
I Class design. The class designer adds details to the analysis model in accordance with
the system design strategy. The class designer elaborates both domain and application
objects using the same OO concepts and notation, although they exist on different con-
ceptual planes. The focus of class design is the data structures and algorithms needed to
implement each class. For example, the class designer now determines data structures
and algorithms for each of the operations of the Window class.
I Implementation. Implementers translate the classes and relationships developed dur-
ing class design into a particular programming language, database, or hardware. Pro-
gramming should be straightforward, because all of the hard decisions should have al-
ready been made. During implementation, it is important to follow good software engi-
neering practice so that traceability to the design is apparent and so that the system
remains flexible and extensible. For example, implementers would code the Window
class in a programming language, using calls to the underlying graphics system on the
workstation.
OO concepts apply throughout the system development life cycle, from analysis through de-
sign to implementation. You can carry the same classes from stage to stage without a change
of notation, although they gain additional details in the later stages. The analysis and imple-
mentation models of Window are both correct, but they serve different purposes and repre-
sent a different level of abstraction. The same OO concepts of identity, classification,
polymorphism, and inheritance apply throughout development.
Note that we are not suggesting a waterfall development process-first capturing re-
quirements, then analyzing, then designing, and finally implementing. For any particular part
of a system, developers must perform each stage in order, but they need not develop each part
of the system in tandem. We advocate an iterative process--developing part of the system
through several stages and then adding capability.
Some classes are not part of analysis but are introduced during design or implementation.
For example, data structures such as trees, hash tables, ard linked lists are rarely present in
the real world and are not visible to users. Designers introduce them to support particular al-
gorithms. Such data structure objects exist within a computer and are not directly observable.
We do not consider testing as a distinct step. Testing is important, but it must be part of
an overall philosophy of quality control that occurs throughout the life cycle. Developers
must check analysis models against reality. They must verify design models against various
kinds of errors, in addition to testing implementations for correctness. Confining quality con-
trol to a separate step is more expensive and less effective.
Chapter 1 / lntroduction
1.3 OO Themes
Several themes pervade OO technology. Although these themes are not unique to OO sys-
tems, they are particularly well supported.
7.3.7 Abstroction
Abstracti.on lets you focus on essential aspects of an application while ignoring details. This
means focusing on what an object is and does, before deciding how to implement it. Use of
absffaction preserves the freedom to make decisions as long as possible by avoiding prema-
ture commitments to details. Most modern languages provide data abstraction, but inherit-
ance and polymorphism add power. The ability to abstract is probably the most important
skill required for OO development.
7.3.2 Errcapsulo;tion
Encapsulation (also information hiding) separates the external aspects of an object, that are
accessible to other objects, from the internal implementation details, that are hidden from
other objects. Encapsulation prevents portions of a program from becoming so interdepen-
dent that a small change has massive ripple effects. You can change an object's implementa-
1.3 OO Themes
tion without affecting the applications that use it. you may want to change the
implementation of an object to improve performance, flx a bug, consolidate code, or support
porting. Encapsulation is not unique to OO languages, but the ability to combine data struc-
ture and behavior in a single entity makes encapsulation cleaner and more powerful than in
prior languages, such as Forffan, Cobol, and C.
,@r
data structure hierarchy
,,N---
/,ANA
replaced
bYr fml
class hierarchy
---'--'l
AI\ l//lN
procedure hierarchy
OA approach OO approach
7.3.4 Shoring
- -
OO techniques promote sharing at different levels. Inheritance ofboth data structure and be-
havior lets subclasses share corlmon code. This sharing via inheritance is one of the main
advantages of OO languages. More important than the savings in code is the conceptual clar-
ity from recognizing that different operations are all really the same thing. This reduces the
number of distinct cases that you must understand and analyze.
OO development not only lets you share information within an application, but also of-
fers the prospect ofreusing designs and code on future projects. OO development provides
the tools, such as abstraction, encapsulation, and inheritance, to build libraries of reusable
Chapter 1 / lntroduction
7.3.6 Sgnergg
Identity, classification, polymorphism, and inheritance charucteize OO languages. Each of
these concepts can be used in isolation, but together they complement each other synergisti-
cally. The benefits of an OO approach are greater than they might seem at first. The emphasis
on the essential properties of an object forces the developer to think more carefully and deep-
ly about what an object is and does. The resulting system tends to be cleaner, more general,
and more robust than it would be if the emphasis were only on the use of data and operations.