Professional Documents
Culture Documents
2.0 INTRODUCTION
Strategies that are selected in system design are carried out in object-oriented design.
In this process, objects that are identified during the analysis are implemented in a
way that it minimizes memory, execution time and other associated costs. All this is
done by the selection of appropriate algorithms, optimizations, and by enforcing
proper. Controls.
In this unit, we will cover the concepts of object design for process, proper algorithm
selections, design optimization and control implementation, with proper adjustment of
inheritance.
2.1 OBJECTIVES
After going through this unit, you should be able to:
explain the steps of object design;
discuss algorithms that minimize costs;
select appropriate data structure to the algorithm;
define new internal classes and operations;
assign responsibility for operation to the appropriate classes; and
explain different types of associations.
21
Object Oriented Design The algorithm designer must:
i) Select the proper algorithm so as to minimize implementation cost
ii) Find the most appropriate data structure for the selected algorithm
iii) Define new internal classes and operations, if required
iv) Assign responsibility for operations to appropriate classes.
b. Collection of entities
c. Constructing physical modules with strong coupling within each module.
Algorithm selection is a very important part of design. It reflects the happening in the
system. In the next section we will discuss algorithm selection.
24
For each operation, we should know the followings: Object Design
How frequently is the operation needed, and how much will it cost?
What is the fan-out along a path through the network? To find fan-out of the
complete path, multiply the average count of each many associations found in
the path with individual fan-outs.
What are the objects that satisfy the selection criteria (if specified) and are
operated on? When most of the objects are rejected during traversal for some
reason, then a simple nested loop may be inefficient at finding target objects.
b) Rearranging the Execution Order for Efficiency
As we already know algorithm and data structure are closely related to each other, but
data structure is considered as the smallest but very important part of algorithm. Thus,
after optimizing the data structure, we try to optimize the algorithm itself.
In general, algorithm optimization is achieved by removing dead paths as early as
possible. For this, we sometimes reverse the execution order of the loop from the
original functional model.
c) Saving Derived Attributes to Avoid Recomputation
Data which is derived from other data should be stored in computed form to avoid
re-computation. For this, we can define new classes and objects, and obviously, these
derived classes must be updated if any base object is changed.
Attribute Attribute
Attribute
{ordered} text list {ordered} Text /
Class box
location
Class box region
{ordered}
Location
Operation location
Operation
text list {ordered} Operation
region Text /
location
Figure 1 shows a use of derived object and derived attribute in OOM. Each class
box contains an ordered list of attributes and operations, each represented as a next
string (Figure 1(a)). We can find the location of any attribute by adding the size of all
elements in front of it, to the location of the class box itself [note: it is quite similar to
the array address calculation]. If a new attribute string is added to the list, then the
locations of the ones after it in the list are simply offset by the size of the new
element. If an element is moved or deleted, the elements under it must be redrawn.
Overlapping elements can be found by scanning all elements in front of the deleted
element in the priority list for the sheet and comparing them to the deleted element.
If the number of elements is large, this algorithm grows linearly in the number of
elements.
As discussed earlier, the change in base object should update the related derived
classes. There are three ways to know when an update is required: by explicit code,
by periodic recomputation, or by using active values.
Explicit update: Every derived attribute is expressed as set of basic base objects. The
designer finds the derived attributes that were affected by change in basic attributes.
Then, he inserts code into the update operation on the base object to explicitly update
the depending derived attributes.
Periodic re-computation: Generally, base values are updated in groups. Thus, all the
derived attributes can be recomputed periodically, instead of after every base value
change.
25
Object Oriented Design Active Value: An active value is a value that has dependent values and update
operations. Each dependant value is registered to an action value. Updation operation
of base value triggers that updates of all dependant values and the calling code need
not explicitly invoke the updates.
2) What are the ways of finding out whether an update is required or not for
derived attributes?
Every program passes through several states, and these states are defined by
implementing appropriate controls. In the next section, we will discuss
implementation of controls.
26
2.6.3 Control as Concurrent Tasks Object Design
As you know, any object can be implemented as a task in the programming language,
or operating system. This is the most general approach because it keeps the inherent
concurrency of real objects. Events are implemented as inter-task calls and as such,
the task uses its location within the program to keep track of its state.
As we have discussed adjusting inheritance is one of the steps of object design. In the
next section, we will discuss how inheritance is adjusted.
i) Some operations needs less arguments than other similar operations, like
drawing an object, e.g., circle, rectangle, etc., with, or without, color fill. Thus,
the attribute color can be accepted, or ignored for consistency with color
displays.
ii) Some operations need less argument than other, because they are special case of
general arguments. Thus, varied newer operation can be implemented by calling
general operation and new argument values. For example, insertion in the
beginning or end of the list are special cases of insertion in the list.
iii) Different classes can have similar attributes, but different names. Thus, they can
be combined and placed in the base class so that the operation to access the
attribute may match in different classes.
27
Object Oriented Design
2.8 DESIGN OF ASSOCIATIONS
Before designing associations, it is necessary to know the way they are used. For this,
analysis of association traversals is necessary. It also important to find out whether the
association is one-way association or two-way association.
2.8.1 Analyzing Association Traversal
Till now, we have assumed that associations are bi-directional. But in the case of
traversal in only one direction in any application, the implementation becomes easier.
However, for finding unidirectional associations we need to be extra cautious, as any
new operation added later may be required to traverse the association in the opposite
direction also. The bi-directional association makes modification, or expansion easier.
To change our decision of implementation strategy with minimum effort, we should
hide the implementation, using access operations to traverse and update the
association.
2.8.2 One-way Associations
When an association is traversed in only one direction, then it is implemented as a
pointer, i.e., an attribute that contains an object reference. If the multiplicity is one
as shown in Figure 2, then it is simple pointer; otherwise it is a set of pointers.
Work-for
Teacher School
Teacher School
Teacher School
English_ Students
Teacher
Set
English Students
28
Implementing it as a distinct association object, i.e., independent of either class Object Design
as shown in Figure 4. The association object may be implemented using two
objects: one in forward direction, and the other in the reverse direction. This
increases efficiency when hashing is used, instead of attribute pointer.
Teacher (School)
Teacher
Teacher
Teacher (School)
Teacher
Figure 4: Implementation of association as an object
This approach is suitable in situations where modify action is minimal, or almost nil.
2.9 SUMMARY
This unit explains that the design model is driven by the relevance to computer
implementation. The design model must be reasonably efficient and practical to
encode. It consists of optimizing, refining and extending the object model, dynamic
model and functional model until they are detailed enough for implementation.
In this unit, we have discussed the steps taken in object design: what the approach
should be for algorithm selections, how design is optimized by providing efficient
access and rearranging execution order, by avoiding recomputation. This unit also
discussed controls implementations, and in the last section of this unit, issues related
to design of associations were discussed.
2.10 SOLUTIONS/ANSWERS
Check Your Progress 1
1) The three models that are used to define operations on classes are:
Object Model = Object model diagram + data dictionary
Dynamic Model = State diagrams + global event flow diagram
Functional Model = Data flow diagrams + constraints.
2) Object design is a very interactive process, which decides the relationship
between objects, classifies operations on classes, designs algorithms
associations, and determines overall system representation.
29
Object Oriented Design 3) To readjust the inheritance the following steps should be taken:
i) Rearrange and adjust classes operations to increase inheritance.
ii) Abstract common behaviour out of groups of classes.
Flexibility.
2) The ways to find out whether an update is required or, not are:
Explicit update
Periodic recomputation
Active values
3) One example of active value is gross salary, which has values as TA, DA, HRA,
etc.
Check Your Progress 3
1) a) Finding main control path
b) Finding conditional statements
c) Finding loops
d) Finding exception handling, and error routines.
2) a) Some attributes can be added, or ignored in base class operation
b) Some variations can be made in derived class from abstract classs.
c) If an operation is not required by some classes in a group, then can it be
declared as no-operation.
d) Similar attributes can be combined in one abstract base class.
3) Two-way association has following advantages:
a) Independent of classes.
b) Useful for existing predefined classes which are not modified.
30
Advance Object Design
UNIT 3 ADVANCE OBJECT DESIGN
Structure Page Nos.
3.0 Introduction 31
3.1 Objectives 31
3.2 Control and its Implementation 32
3.2.1 Control as a State within Program
3.2.2 Control as a State Machine Engine
3.2.3 Control as Concurrent Task
3.3 Inheritance Adjustment 35
3.4 Association: Design 37
3.5 Object Representation 38
3.6 Design Optimization 39
3.7 Design Documentation 43
3.8 Summary 43
3.9 Solutions/Answers 45
3.0 INTRODUCTION
As discussed earlier analysis is the first step of the OMT methodology. It is concerned
with devising a precise, concise, understandable and correct model of the realworld.
For example, before building any complex thing, such as a house, a bridge, or a
hardware-software system, the builder must understand the requirement of the user,
and it is also necessary to know the realworld environment in which it will exist.
The advanced object design is a complex task. The objects discovered during analysis
serve as a skeleton of the design. The operations identified during analysis should be
expressed as algorithms. Advanced object oriented design is basically a process of
refinement, or adding the details to the body of an object.
In this unit, you will learn how to design a formal and rigorous model of real-world
problems by applying the findings of the analysis phase of OMT. The object design
phase determines the complete definition of classes and associations used in the
implementation. The advanced object design is a process to create architecture of the
realworld problems. The advanced object design is analogous to the preliminarily
design phase of the traditional software development cycle.
3.1 OBJECTIVES
After studying this unit, you should be able to:
combine the three OOAD models to obtain operations on classes;
design algorithms to implement operations on classes;
optimize access paths to data;
implement control for external interactions;
adjust class structure to increase inheritance;
design association;
determine object representation, and
package classes and association into modules.
31
Object Oriented Design
3.2 CONTROL AND ITS IMPLEMENTATION
In this unit, we will start our discussion with explanation of state-event models.
Let us define an state-event model. State-event model is a model which shows the
sequence of events happening on an object, and due to which there are changes in the
sate of an object. In the state-event model, the events may occur concurrently and
control resides directly in several independent objects. As the object designer you
have to apply a strategy for implementing the state event model. There are three basic
approaches to implementing system design in dynamic models. These approaches are
given below:
Using the location within the program to hold state (procedure-driven system).
Direct implementation of a state machine mechanism (event-driven system).
Using concurrent tasks.
a) Identify all the main control paths. Start from the initial state; choose a path
through the diagram that corresponds to the normally expected sequence of
events. Write the names of states along the selected path as a linear sequence.
This will be a sequence of statements in the program.
b) Choose alternate paths that branch off the main path of the program and rejoin it
later. These could be conditional statements in the program.
c) Identify all backward paths that branch off the main loop of the program and
rejoin it earlier. This could be the loop in the program. All non-intersecting
backward paths become nested loops in the program.
32
Main Screen
Advance Object Design
insert card
Request Password
enter password
Verify account
account OK
bad account
Request type
enter type
Request amount
enter amount
Process transaction
transaction failed transaction succeed
Dispense cash
take cash
Request continuation
Finish
Card rejected
33
Object Oriented Design These lines are the pseudocode for the ATM control loop, which is another form of
representation of Figure 1. Furthermore, you can add cancel event to the flow of
control, which could be implemented as goto exception handling code. Now, let us
discuss controls as a state machine engine.
3.2.2 Control as a State Machine Engine
First let us define state machine: the state machine is an object but not an
application object. It is a part of the language substrate to support the syntax of
application object. The common approach to implement control is to have some way
of explicitly representing and executing state machines. For example, a general state
machine engine class could provide the capability to execute a state machine
represented by a table of transitions and actions provided by the application. As you
know, each object contains its own independent state variable and could call on the
state engine to determine the next state and action.
This approach helps to quickly progress from the analysis model to a skeleton
prototype of the system by defining classes from the object model, state machines
from the dynamic model, and creating stubs of the action routines. A stub could be
stated as the minimal definition of a function or subroutine without any internal
code. Thus, if each stub-prints out its name, this technique allows you to execute the
skeleton application to verify that the basic flow of control is correct or not.
State machine mechanisms can be created easily using an object oriented language.
3.2.3 Control as Concurrent Tasks
The term control as concurrent task means applying control for those events of the
object that can occur simultaneously. An object can be implemented as a task in the
programming language or operating system. This is the most general approach of
concurrency controls. With this you can preserve the inherent concurrency of real
objects. You can implement events as inter-task calls using the facilities of the
language, or operating system.
As far as OO programming languages are concerned, there are some languages, such
as Concurrent Pascal or Concurrent C++, which support concurrency, but the
application of such languages in production environments is still limited. Ada
language supports concurrency, provided an object is equated with an Ada task,
although the run-time cost is very high. The major object oriented languages do not
yet support concurrency.
34
Advance Object Design
3.3 INHERITANCE ADJUSTMENT
As you know in object oriented analysis and design the terms inheritance defines a
relationship among classes, wherein one class shares the structure or behavior defined
in one or more classes. As object design progresses, the definitions of classes and
operations can often be adjusted to increase the amount of inheritance. In this case, the
designer should:
Rearrange and adjust classes and operations to increase inheritance
Abstract common behavior out of groups of classes
Use delegation to share behavior when inheritance is semantically invited.
You will find that some operations may have fewer arguments than others. The
missing arguments can be added but ignored. For example, a draw operation on
a monochromatic display does not need a color parameter, but the parameter can
be accepted and ignored for consistency with color displays.
Some operations may have fewer arguments because they are special cases of
more general arguments. In this case, you may implement the special operations
by calling the general operation with appropriate parameter values. For
example, appending an element to a list is a special case of inserting an element
into list; here the insert point simply follows the last element.
Similar attributes in different classes may have different names. Give the
attributes the same name and move them to a common ancestor class. Then
operations that access the attributes will match better. Also, watch for similar
operations with different names. You should note that a consistent naming
strategy is important to avoid hiding similarities.
An operation may be defined on several different classes in a group, but be
undefined on the other classes. Define it on the common ancestor class and
declare it as a no-op on the classes that do not care about it. For example, in
OMTool the begin-edit operation places some figures, such as class boxes, in a
special draw mode to permit rapid resizing while the text in them is being
edited. Other figures have no special draw mode, so the begin-edit operation on
these classes has no effect.
When common behavior has been recognised, a common super class can be created
that implements the shared features, leaving only the specialised features in the
subclasses. This transformation of the object model is called abstracting out a
common super class or common behavior. Usually, the resulting super class is
abstract, meaning that there are no direct instances of it, but the behavior it defines
belongs to all instances of its subclasses. For example, again we take a draw operation
35
Object Oriented Design of a geometric figure on a display screen requires setup and rendering of the
geometry. The rendering varies among different figures, such as circles, lines, and
spines, but the setup, such as setting the color, line thickness, and other parameters,
can be inherited by all figure classes from abstract class figure.
The creation of abstract super classes also improves the extensibility of a software
product, by keeping space for further extension on base of abstract class.
List
Body: list {private} List
Stack
Push
pop
Discouraged Recommended
Figure 2: Alternative implementations of a Stack using inheritance (left) and delegation (right)
36
By Figure 2, it is obvious that we should discourage the use of inheritance to share the Advance Object Design
operations between two related classes. Instead, we should use delegation so that one
class can selectively invoke the desired functions of another class. Now, you are
aware of the concept of inheritance and its adjustment. In the next section, we will
discuss association design and different types of associations.
Person Company
Works-for
Person Company
Employer employees
Two-way Associations
Many associations are traversed in both directions, and these are called two-way
associations. You may observe that it is not essential to have some frequency of
traversal from both sides. It can be implemented by using the following three
methods:
37
Object Oriented Design
Person Work for Company
Person Company
Employer Employees
Set
(Person) (Company)
(Person)
(Person)
(Person)
(Company)
(Person)
We can define a class in terms of other class. The classes must be implemented in
terms of built-in primitive data types, such as integers, strings, and enumerated types.
For example, consider the implementation of a social security number within an
employee object which is shown in Figure 6. The social security number attribute can
be implemented as an integer or a string, or as an association to a social security
number object, which itself can contain either an integer or a string. Defining a new
class is more flexible, but often introduces unnecessary indirection. It is suggested that
new classes should not be defined unless there is a definite need it.
38
Advance Object Design
Employee Employee SSN SS number
In a similar way, the object designer decides whether to combine groups of related
objects or not.
39
Object Oriented Design Adding Redundant Associations for Efficient Access
The term redundant association means using duplicate association for efficient
access. During analysis, it is not a good idea to have redundancy in the association
network because redundant associations do not add any information. During design,
however, you should evaluate the structure of the object model for implementation.
This can be done by asking questions:
i) Is there a specific arrangement of the network that would optimize critical
aspects of the completed system?
ii) Will adding new associations that were useful during analysis restructure the
network? All this sometimes may not produce the most efficient network, one
that can handle complex access patterns, as well as the related frequencies of
various kind of access.
To describe the analysis of access paths, consider the example of the design of a
companys employee skills database. A part of the object model from the analysis
phase is shown in Figure 7. The operation Company:: find-skill returns a set of
persons in the company with a given skill. For example, we may ask for the data of all
employees who speak Japanese.
Employs Has-skill
Company Person Skill
For this example, suppose that the company has 1000 employees, each of whom has
10 skills on average. A simple nested loop would traverse Employs 1000 times and
Has-skill 10,000 times. If only 5 employees actually speak Japanese, then the test-to-
hit ratio is 2000.
Now, let us see whether this figure can be improved or not. Actually, we can make
many possible improvements in this Figure. First, Has-skill need not be implemented
as an unordered list a hashed set. The hashing can be performed in a fixed interval of
time so that the cost of testing whether a person speaks Japanese is constant, provided
a unique skill object represents speaks Japanese. This rearrangement reduces the
number of tests from 10,000 to 1,000, or one per employee.
For those cases where the number of hits from a query is low (since only a fraction of
objects satisfy the test) we can build an index to improve access to objects that must
be frequently retrieved. For example, we can add a qualified association Speaks
language from Company to Employee, where the qualifier is the language spoken
(Figure 8). This permits us to immediately access all employees who speak a
particular language with no wasted accesses. But there is a cost to the index: It
requires additional memory, and it must be updated whenever the base associations
are updated. The object designer must decide when it is useful to build indexes.
Here, we have to consider the case where most queries return all of the objects in the
search path, then an index really does not save much because the test-to-hit ratio in
this case is very close to 1.
Speak language
Company language
40
You can analyse the use of paths in the association network in the following steps: Advance Object Design
Examine each operation and see what associations must traverse in order to
obtain information. For this it is not necessarily those associations traverse in
both directions.
For each operation, you should note the following points:
How often is the operation called? How costly is the operation to perform?
What is the fan-out along a path through the network? Estimate the average
count of each many association encountered along the path. Multiply the
individual fan-outs to obtain the fan-out of the entire path, which represents the
number of accesses on the last class in the path. Note that one links do not
increase the fan-out, although they increase the cost of each operation slightly.
But there is no need to worry about such small effects.
What is the fraction of hits on the final class, (objects that meet selection
criteria, if any, and are operated on? If most objects are rejected during the
traversal for some reason, then a simple nested loop may be inefficient for
finding target objects.
Rearrange the Execution Order for Efficiency
Rearranging the execution order for efficiency means executing such job which has
less execution time. By rearranging the object in the increasing order of their
execution time, we can increase the efficiency of the system.
After adjusting the structure of the object model to optimize frequent traversals, the
next thing to optimize is the algorithm itself. Actually, data structure and algorithms
are directly related to each other, but we find that usually the data structure should be
considered first.
The way to optimize an algorithm is to eliminate dead paths as early as possible.
For example, suppose we want to find all employees who speak both Japanese and
French, and suppose 5 employees speak Japanese and 100 speak French. In this case,
it is better to test and find the Japanese speakers first, then test if they speak French. In
general, it pays to narrow the search as soon as possible. Sometimes the execution
order of a loop must be inverted from the original specification in the functional
model to get efficient results.
Saving Derived Attributes to Avoid Recomputation
As we have already discussed, redundancy means duplication of same data. But, If
multiple copies of the same data is present in a system, then it can increase
availability of data, but the problem of computing overhead is also associated with it.
To overcome this problem we can cache or store redundant data in its computed
form and objects or classes may be defined to retain this information. The class that
contains the cached data must be updated if any of the objects that it depends on are
changed.
Figure 9 shows a use of a derived object and derived attribute in OMTool. Each class
box contains an ordered list of attributes and operations, each represented as a text
string (left of diagram). Given the location of the class box itself, the location of each
attribute can be computed by adding up the size of all the elements in front of it. Since
the location of each element is required frequently, the location of each attribute string
is computed and stored. The region containing the entire attribute list is also computed
and saved. In this way we can avoid the testing of input points against attribute text
element. It is shown on the right side in Figures 9 (a) and (b). If a new attribute string
is added to the list, then the locations of the ones after it in the list are simply offset by
the size of the new element.
41
Object Oriented Design {ordered} Attribute Attribute Attribute
list
Text
Class box text Region
Class box location
Location location
Operation Operation
list Operation
text region
Region
Location
You can see the use of an association as a cache which is shown in Figure 10. In this
figure a sheet contains a priority list of partially overlapping elements. If an element is
moved or deleted, the elements under it must be redrawn. Scanning all elements in
front of the deleted element in the priority list of the sheet, and comparing them to the
deleted element can uncover overlapping elements. If the number of elements is large,
this algorithm grows linearly in the number of elements. The Overlaps association
stores those elements that overlap an object, and precede it in the list. This association
must be updated when a new element is added to it, but testing for overlap using the
association is more efficient.
Priority
list
next
Diagram
element Previous
over
under
Overlaps
After the base value is changed, you should update derived attributes. Now, the
question is how to recognise the need of update. There are three ways to recognize
when an update is needed: by explicit code, by periodic recomputation, or by using
active values. Now, let us three ways one by one.
Explicit update: In explicit update, each derived attribute is defined in terms of
one, or more fundamental base object(s). The object designer determines which
derived attributes are affected by each change to a fundamental attribute, and
inserts code into the update operation on the base object to explicitly update the
derived attributes that depend on it.
Periodic recomputation: Base values are often updated in bunches.
Sometimes, it is possible to simply recompute all the derived attributes
periodically without recomputing derived attributes after each base value is
changed. Recomputation of all derived attributes can be more efficient than
incremental update because some derived attributes may depend on several base
attributes, and might be updated more than once by an incremental approach.
Also, periodic recomputation is simpler than explicit updates and less prone to
bugs. On the other hand, if the data set changes incrementally, a few objects at a
time, periodic recomputation is not practical because too many derived
attributes must be recomputed when only a few are affected.
Active values: An active value is a value that has dependent values. Each
dependent value registers itself with the active value, which contains a set of
dependent values and update operations. An operation to update the base value
triggers updates of all the dependent values, but the calling code need not
explicitly invoke the updates.
Now, let us discuss design documentation in the designing of an object.
42
Advance Object Design
3.7 DESIGN DOCUMENTATION
The Design Document should be an extension of the Requirements Analysis Design.
The Design Document will include a revised and much more detailed
description of the Object Model in both graphical form (object model diagrams)
and textual form (class descriptions). You can use additional notation to show
implementation decisions, such as arrows showing the traversal direction of
associations and pointers from attributes to other objects.
The Functional Model can also be extended during the design phase, and it must be
kept current. It is a seamless process because object design uses the same notation as
analysis, but with more detail and specifics. It is good idea to specify all operation
interfaces by giving their arguments, results, input-output mappings, and side effects.
Despite the seamless conversion from analysis to design, it is probably a good idea to
keep the Design Document distinct from the Analysis Document. Because of the shift
in viewpoint from an external users view to an internal implementers view, the
design document includes many optimizations and implementation artifacts. It is
important to retain a clear, user-oriented description of the system for use in validation
of the completed software, and also for reference during the maintenance phase of the
object modeling.
Ellipse Rectangle
Boundary
.
..
2) Assign a data type to each attribute in Figure 12.
Page Column Line
.
..
43
Object Oriented Design 3) Improve the object diagram in Figure 13 by transforming it, adding the class
(Political party). Associate Voter with a party. Discuss why the transformation
is an improvement.
Voter
.
..
..
..
4) Figure 14 is a state diagram for a garage door opener. Implement it by using
state as, location within a program. You may use pseudocode, or any structured
programming language.
Closed Open
Depress/start opening door
Closing
Door closed Depress/start opening door
3.8 SUMMARY
Object design follows analysis and system design. The object design phase adds
implementation details, such as restructuring classes for efficiency, internal data
structures and algorithms to implement operations, implementation of control,
implementation of associations, and packaging into physical modules. Object design
extends the analysis model with specific implementation decisions and additional
internal classes, attributes, associations, and operations.
During object design, the definitions of internal classes and operations can be adjusted
to increase the amount of inheritance. These adjustments include modifying the
argument list of a method, moving attributes and operations from a class into a super
class, defining an abstract super class to cover the shared behavior of several classes,
and splitting an operation into an inherited part and a specific part. Delegation should
be used rather than inheritance when a class is similar to another class but not truly a
sub class.
44
Associations are the glue of our object model, which provides access paths between Advance Object Design
objects. An association traversed in a single direction can be implemented as an
attribute pointing to another object, or a set of objects, depending on the multiplicity
of the association. A bi-directional association can be implemented as a pair of
pointers, but operations that update the association must always modify both
directions of access. Associations can also be implemented as association objects.
The exact representation of objects must be chosen. At some point, user-defined
objects must be implemented in terms of primitive objects, or data types supplied by
the programming language. Some classes can be combined. Programs must be
packaged into physical modules for editors and compilers, as well as for the
convenience of programming teams. Design decisions should be documented by
extending the analysis model, by adding detail to the object, dynamic, and functional
models.
3.9 SOLUTIONS/ANSWERS
Check Your Progress 1
1) State Diagram
An object can receive a sequence of input instructions. The state of an object can vary
depending upon the sequence of input instructions. If we draw a diagram which will
represent all the processes (input) and their output (states) then that diagram is known
as state diagram. Processes are represented by arrow symbol, and states by oval
symbol. For example, the screen of ATM machine has many states like main screen
state, request password state, process transaction state, etc.
2) Concurrent Task
The simultaneous occurrence of more than one event is called a concurrent task.
Operating systems can handle concurrent tasks efficiently. The Air Traffic Control
system (ATC) for examples, can manage concurrent tasks in fractions of a second.
3) Event
Happening of a process is called event. In other words, an object can receive many
input instructions. The changes that occur due to these instructions are called events.
For example, tossing a coin is input, but the appearance of HEAD or TAIL is an
event.
State
The position of an object at any moment is called its state. An object can have many
states. After receiving some input instructions, an object can change its state from one
to another.
Check Your Progress 2
1) Inheritance
Inheritance is one of the cornerstones of object-oriented programming language
because it allows a creation of hierarchical classifications. Using inheritance you can
create a general class that defines trails common, to a set of related items. More
specific classes can inherit this class, and each could add a certain unique thing to the
resulting new class. The class that inherits from another, class, or classes is called a
derived class or subclass, and the class/classes from which the derived class is made is
called, a base class or a super class.
For example, racing cars. Pick up cars and saloons, etc. are all different kinds of cars
in object-oriented terminology racing cars. Pick up cars, and saloons, etc. are all
subclasses of the car class. Similarly, as illustrated in Figure15, below, the car class is
the super class of sub classes like racing cars, saloons, sedans, convertibles, etc.
45
Object Oriented Design
Cars Cars
A A
B B C D
A B
B
C C
In the above example, there are two objects, person and company. These two objects
are linked (associated) with each other by a relation called works for.
46
Advance Object Design
3) Adjustment of Inheritance
The definition of classes and operations can often be adjusted to increase the amount
of inheritance between the objects. The object designer can rearrange and adjust
classes to increase the inheritance among the different objects and classes. Sometimes
the same operation is defined across several classes and can easily be inherited from a
common ancestor. By slightly modifying the definitions of the operations, or the
classes, the operation often can be made to match. We also can extract common
behavior out of groups of classes to increase the inheritance. Similar attributes in
different classes may have different names, but by giving some common name and
moving them to ancestor class we can increase inheritance. An operation may be
defined on several different classes in a group but be undefined on the other classes.
To increase inheritance, we can define it on the common ancestor class and declare it
as a no-op on the classes that do not care about it. We can also use DELEGATION
instead of inheritance to share only meaningful attributes between a super class and its
sub class.
Check Your Progress 3
1) The improved generalized object diagram of class Ellipse and Rectangle is
given in the Figure below.
Graphics Boundary
Primitive
Boundary Boundary
Here, in this diagram, class Graphics primitive is the generalized class of both Ellipse
and Rectangle. The class Ellipse and Rectangle have single association with class
boundary. This single association is shown by drawing a line between class boundary
and generalized class Graphics primitive.
2) A derived association supports direct traversal from Page to Line. The line-page
association is derived by composing the line column and column page
association.
This association can be traversed from lines to pages. The Figure is shown below.
Member Register in
Voter Political
Party
Figure 20: Improved object diagram for representing voter membership in a political party
In the above pseudo code we are using go to as a jump command to jump from one
statement to other.
48
System Design
1.0 INTRODUCTION
Object oriented design (OOD) is concerned with developing an object oriented model
of a software system to implement the identified requirements. Many OOD methods
have been described since the late 1980s. The most popular OOD methods include
Booch, Buhr, Wasserman, and the HOOD method developed by the European Space
Agency which can yield the following benefits: maintainability through simplified
mapping to the problem domain, which provides for less analysis effort, less
complexity in system design, and easier verification by the user. OOD also provides
reusability, which saves time and costs, and productivity gains through direct
mapping to features of Object-Oriented Programming Languages. Object Oriented
Development (OOD) has been touted as the next great advance in software
engineering. It promises to reduce development time, reduce the time and resources
required to maintain existing applications, increase code reuse, and to provides a
competitive advantage to organizations that use it. While the potential benefits and
advantages of OOD are real, excessive hype has lead to unrealistic expectations
among executives and managers. Even software developers often miss the subtle, but
profound, differences between OOD and classic software development.
In this Unit we will discuss the basics of object oriented design. We will learn how
systems are broken into subsystems, concurrency identification, and how data storage
is managed.
1.1 OBJECTIVES
After going through this unit, you should be able to:
give an overview of object oriented design;
breaking down system to subsystems;
explain how a software design may be represented as a set of interacting
objects that manage their states and operation;
identify concurrent object, and explain how to handle concurrency;
explain methods of storing data and comparison with conventional system
design;
control events between objects; and
explain boundary condition.
5
Object Oriented Design
Any software systems always tends to change and evolve as technology and business
rules change. The evolution of information systems is unavoidable, and it is a natural
phenomenon. Organisations need to support systems evolution to take advantage of
the new technology and to address the changing business rules. The evolutionary
nature of software products requires us to maintain products with their continually
changing nature. Not all software products developed are amenable to these fast
changes. In this ever-increasing competitive business environment, there is hardly
any option but to adopt technology that is adaptable to changes.
Software systems designed with structured design methodology do not support
some of the desired quality attributes such as reusability, portability and mapping to
the problem domain. Many large organisations find that systems designed with
structured approaches are less reusable and less maintainable than those designed
with object-oriented approaches.
OOD techniques are useful for development of large, complex systems. It has been
observed that large projects developed using OOD techniques resulted in a 30%
reduction in development times and a 20% reduction in development staff effort,
as compared to similarly sized projects using traditional software development
techniques.
Although object oriented methods have roots that are strongly anchored back in the
60s, structured and functional methods were the first to be used. This is not very
uncommon, since functional methods are inspired directly by computer
architecture (a proven domain, well known to computer scientists). The separation
of data and program as exists physically in the hardware was translated into
functional methods. This is the reason why computer scientists got into the habit of
thinking in terms of system functions. Later it was felt that hardware should act as
the servant of the software that is executed on it rather than imposing architectural
constraints on system development process.
Moving from a functional approach to an object oriented one requires a translation of
the functional model elements into object model elements, which is far from being
straightforward or natural. Indeed, there is no direct relationship between the two
sets, and it is, therefore, necessary to break the model elements from one approach in
order to create model element fragments that can be used by the other. In the initial
phases of OO design a mixed approach was followed computer scientist tend to use
functional approach in analysis phase and OO approach in design phase. The
combination of a functional approach for analysis and an object-oriented approach for
design and implementation does not need to exist today, as modern object-oriented
methods cover the full software lifecycle.
Traditional System Analysis and Design: Traditional System Analysis and Design
(SAD) has three fundamental life cycle models. A typical software lifecycle consists
of following phases:
Planning
Development
Maintenance
Key Criteria
a well-defined methodology
traceability among steps
documentation
control
Software Life Cycle
The software design consists of a number of stages, or phases
1. Requirement Phase determine use need
2. Specification Phase define requirement
6
System Design
The first few years of the 1990s saw the blossoming of around fifty different object
oriented methods. This proliferation is a sign of the great vitality of object oriented
technology, but it is also the fruit of a multitude of interpretations of exactly what an
object is. The drawback of this abundance of methodologies is that it encourages
confusion, leading users to adopt a wait and see attitude that limits the progress
made by the methods. The best way of testing something is still to deploy it; methods
are not cast in stone they evolve in response to comments from their users.
Fortunately, a close look at the dominant methods allows the extraction of a
consensus around common ideas. The main characteristics of objects, shared by
numerous methods, are articulated around the concepts of class, association
(described by James Rumbaugh), partition into subsystems (Grady Booch), and
around the expression of requirements based on studying the interaction between
users and systems (Ivar Jacobsons use cases).
Finally, well-deployed methods, such as Booch and OMT (Object Modeling
Technique), were reinforced by experience, and adopted the methodology elements
that were most appreciated by the users.
From SAD to OOAD (Structured Analysis and Design (SAD) to Object Oriented
Analysis and Design (OOAD).
We will see here how we can map different models in SAD to different models in
OOAD. We will a consider various levels of abstraction through which this is done.
The data flow diagram (DFD) in SAD is mapped to Use Case diagram in OOAD.
DFD represents a broader model of a system from the process point of view. Hence,
DFD cannot be transformed as it is to equivalent representation in UML.
External
Actor
entity Use Case
Diagram
7
Object Oriented Design
Software developers, data base administrators (DBAs), need to be familiar with the
basic concepts of object-orientation. The object-oriented (OO) paradigm is a
development strategy based on the concept that systems should be built from a
collection of reusable components called objects. Instead of separating data and
functionality as is done in the structured paradigm, objects encompass both. While
the object oriented paradigm sounds similar to the structured paradigm, as you will
see in this course material it is actually quite different. A common mistake that many
experienced developers make is to applying similar software-engineering principles
to OO design. To succeed one must recognize that the OO approach is different than
the structured approach.
) Check Your Progress 1
8
System Design
...
.
Breaking the system into subsystem involves breaking the problem in to logically
independent and interacting subsystems. Now we will discuss how a system is broken
into subsystems.
Open Deposit
Withdraw
9
Object Oriented Design
Open
Deposit
Withdraw
Account
Other
object(s)
-------- --------
-------- --------
-------- --------
10
System Design
One of the important issues in system design is to find the concurrency in objects.
Once we identify non-concurrent (mutually exclusive) objects, we can fold all the
objects together in one thread of control, or process. On the other hand, if the
objects are concurrent in nature we have to assign them to, different thread of
control. For example, withdraw and deposit operations related to a bank account may
be executed in parallel (concurrently).
11
Object Oriented Design
Example:
calculateNewBalance(300,100) 300
setNewBalance(200) calculateNewBalance(300,100)
setNewBalance(200)
:withdraw c2:customer
c1:customer
:withdraw
withdraw(100)
get balance()
withdraw(100) 300
setNewBalance(200)
get balance()
Refer to the Figure 7 if an object must perform two or more activities concurrently,
then the internal steps of the process must be synchronized. Both the synchronized
activity must complete before the object performing the concurrent activity can go to
the next step.
Concurrency issues
Data integrity: Threads accessing the same object need to be synchronized, for
example: banking account.
Deadlock: One or more threads in the system are permanently blocked
Example: Thread A waiting on Thread B, which is waiting on Thread A.
Starvation: A thread is not getting enough resources to accomplish its work
Example: All requests from one user are being handled before another users
requests.
How to handle concurrency:
Mechanisms
12
System Design
Locks
Semaphores
Monitors
Synchronized methods
Methods
Deadlock avoidance
Verification
Simulation
Key:
1) Develop a clear strategy for dealing with all concurrency issues during system
design.
2) Concurrency must be dealt with during the design process as dealing with
concurrency after the system is implemented is difficult.
A detailed discussion on this topic will be there in MCS 041.
13
Object Oriented Design
Reservation 1 Customer
{persistent} {persistent}
d1 d1
Process Process
The advantage of using a Database Management System for a data store is that
databases have mechanisms for describing data, managing persistent storage and
for providing a backup and recovery mechanism. It also provides concurrent
access to the stored data with an appropriate locking mechanism. Most of the DBMS
contains information about data in the form of a data dictionary. Most commercial
RDBMS come with an Object-Relational extension which implements an object
database on top of a RDBMS.
Issues when Selecting a Database
Storage space requirement: A database requires about triple the storage space
of actual data.
Response time: The response time of the database for I/O or communication
bound (in case of distributed databases) request.
Locking modes pessimistic locking: Lock before accessing an object and
release when object access is complete.
14
System Design
Optimistic locking: Read and writes may freely occur (high degree of
concurrency).
Administration: Modern DBMS requires specially trained support staff to set
up security policies, manage the disk space, prepare backups, fine-tune the
performance, and monitor performance.
How often is the database accessed?
What is the expected request (query) rate? In the worst case?
What is the size of the typical request and of the worst case requests?
Need for data to be archived.
Table 1
Most of the object oriented system use relational database to store persistent data.
The advantages and disadvantages of OO database are compared in Table 2.
Table 2
15
Object Oriented Design
Describes what resources are cleaned up, and which systems are notified upon
termination (termination use cases).
Configuration
Describes how the system is adapted to a local installation.
Failure
Unplanned termination of the system.
16
System Design
StartUpServer
ManageServer
ShutDownServer
System Administrator
ReconfigureServer
ConfigureServer
FineTune
Figure 10: Boundary Use Case
While defining the boundaries of a system we must ascertain what system entities one
does and does not have control over. The level of control is determined for all
identified internal and external entities. The control status can be total, partial, or
none.
1) What is persistency?
2) Why, generally, does an object-oriented system use a relational DBMS?
3) Identify and name a few boundary processes.
17
Object Oriented Design
4) Draw a use case diagram for a typical Flight Reservation System. Identify use
case and actor.
.
1.8 SUMMARY
OOD techniques are useful for the development of large, complex systems. Moving
from a functional approach to an object-oriented one requires a translation of the
functional model elements into object model elements, which is far from being
straightforward. The high-level system design approach involves breaking down the
system into simple and relatively independent sub systems for better manageability.
Systems can be proportioned to horizontal or vertical partitions. Concurrency is
inherent to objects, and concurrent objects cannot be folded into a single thread of
control. Concurrency must be dealt with during the design process as dealing with
concurrency after the system is implemented is difficult.
Most systems need persistent data which is not lost when the system closes down.
Data can be stored in flat files or DBMS. Object-oriented databases provide support
for all fundamental object modeling concepts like Classes, Attributes, Methods,
Associations, and Inheritance. But unlike RDBMS, object-oriented databases lack
theoretical foundation and standards. Although system design is concerned with the
steady state behaviors of the system, the system must be designed to handle boundary
conditions. Boundary use cases are useful to analyse boundary conditions.
18
System Design
3) Concurrency in objects can be identified by the way they change state. Current
objects can change state independently. Aggregation implies concurrency in the
system.
Book
ticket
Confirm
Ticket
Figure 11: Use case for Book Ticket, check schedule and confirm Ticket
19