Designing Algorithms and Data Structures

22.3.2 Designing Algorithms and Data Structures

A variety of representations contained in the analysis model and the system design pro- vide a specification for all operations and attributes. Algorithms and data structures are

designed using an approach that differs little from the data design and component-level Virtually every concept

XRef

presented in Chapter 13

design approaches discussed for conventional software engineering.

is applicable here. Be An algorithm is created to implement the specification for each operation. In many sure you’re familiar

cases, the algorithm is a simple computational or procedural sequence that can be with the topics

presented there. implemented as a self-contained software module. However, if the specification of the operation is complex, it may be necessary to modularize the operation. Conven- tional component-level design techniques can be used to accomplish this.

Data structures are designed concurrently with algorithms. Since operations invari- ably manipulate the attributes of a class, the design of the data structures that best reflect the attributes will have a strong bearing on the algorithmic design of the cor- responding operations.

? Although many different types of operations exist, they can generally be divided

Is there a

way to

into three broad categories: (1) operations that manipulate data in some way (e.g.,

categorize operations adding, deleting, reformatting, selecting), (2) operations that perform a computa-

(methods)?

tion, and (3) operations that monitor an object for the occurrence of a controlling event.

For example, the SafeHome processing narrative contains the sentence fragments: "sensor is assigned a number and type" and "a master password is programmed for arming and disarming the system." These two phrases indicate a number of things:

• That an assign operation is relevant for the sensor object. • That a program operation will be applied to the system object. • That arm and disarm are operations that apply to system (also that system

status may ultimately be defined (using data dictionary notation) as

system status = [armed | disarmed] The operation program is allocated during OOA, but during object design it will be

An operation is refined refined into a number of more specific operations that are required to configure the in much the same way system. For example, after discussions with product engineering, the analyst, and that we refine a

possibly the marketing department, the designer might elaborate the original pro- function in

cessing narrative and write the following for program (potential operations—verbs— conventional design.

Write a processing are underlined): narrative, do a

Program enables the SafeHome user to configure the system once it has been installed. The

grammatical parse, and isolate new user can (1) install phone numbers; (2) define delay times for alarms; (3) build a sensor table

operations at a lower

that contains each sensor ID, its type, and location; and (4) load a master password.

level of abstraction. Therefore, the designer has refined the single operation program and replaced it with the operations: install, define, build, and load. Each of these new operations becomes part of the system object, has knowledge of the internal data structures that implement the object's attributes, and is invoked by sending the object messages of the form

MESSAGE (system) --> install: SENDS telephone.number; This implies that, to provide the system with an emergency phone number, an install

message will be sent to system. Verbs connote actions or occurrences. In the context of object design formaliza- tion, we consider not only verbs but also descriptive verb phrases and predicates (e.g., "is equal to") as potential operations. The grammatical parse is applied recur- sively until each operation has been refined to its most-detailed level.

CHAPTER 22 OBJECT-ORIENTED DESIGN

Once the basic object model is created, optimization should occur. Rumbaugh and his colleagues [RUM91] suggest three major thrusts for OOD design optimization:

• Review the object-relationship model to ensure that the implemented design leads to efficient utilization of resources and ease of implementation. Add redundancy where necessary.

• Revise attribute data structures and corresponding operation algorithms to

enhance efficient processing. • Create new attributes to save derived information, thereby avoiding recom-

putation.

A detailed discussion of OO design optimization is beyond the scope of this book. The interested reader should refer to [RUM91] and [CHA93]. For a discussion of how these concepts translate into the UML process, the reader should examine [JAC99] and [RUM99].