OOSD Unit 3
OOSD Unit 3
GHAZIABAD
OOSD
BCS-054
Unit: 3
OOSD
Selecting Algorithms:
Selecting Data Structure:
Analysis Model
Now if there are 1000 students out of which only 10 students have skills for sports then for
finding sport-persons a simple loop will execute for 1000 times. This leads to inefficient
execution. To eliminate this problem some improvements can be made. For example, we can
create a hashed instead of unordered linked list. Another solution is to create index for
retrieving the objects that are accessed more frequently.
Referring to above example, if we want to find out the students who speak German and play
sport then we need to iterate through the number of students for many times. Naturally we
will get the less efficient model of execution. In order to improve the performance, we can
use the derived association. The derived association does not add useful information but is
used for fast access. Following figure illustrates this idea
Design Model
IMPLEMENTATION OF CONTROL
As part of the system design, the designer must implement state diagram of the dynamic
model. There are three basic approaches to implement it:
To use location within the program to hold state.
Direct implementation of state machine mechanism
Using concurrent tasks
State as location within a program: The location of control within a program can be used to
represent state of the program. Each state transition corresponds to an input statement. The
control of the program branches depending upon the input event received. In highly nested
procedural code, there must be a procedure, which can handle the supplied input. The state
diagram can be converted to code as follows:
a) Identify the main path through the diagram that leads to normal execution of events.
Identify the names of states along this path. This becomes a sequence of statements
in the program.
b) Identify alternate paths, which branch off the main path. This becomes the conditional
statements in the program.
c) To identify the loops, find out backward paths that branch off the main path. Multiple
backward paths become nested loops in the programs.
d) Remaining states and conditions correspond to exceptional conditions. These
exceptional conditions can be handled through exception handling or including error
subroutines.
However, in this approach the lack of modularity is biggest drawback.
The definition of classes and operations can be adjusted to make the inheritance tree as
large as possible. It can be done in the following ways.
Rearranging and adjustment of classes and operations to increase inheritance.
Abstracting common behavior out of group of classes.
Use of delegation to share behavior when inheritance is semantically invalid.
OBJECT REPRESENTATION
The object designer has to choose when to use primitive types in representing the objects or
when to combine the groups of objects. A class can be defined in terms of other classes but
ultimately all data members have to be defined in terms of builtin data types supported by a
programming language. For example, roll no. can be implemented as integer or string. In
another example, a two dimensional can be represented as one class or it can be
implemented as two classes – Line class and Point class.
PHYSICAL PACKAGING
Modularity is the property of a system that has been decomposed into a set of cohesive and
loosely coupled modules. Modules serve as the physical containers in which we declare the
classes and objects of our logical designs. A module can be edited, compiled or imported
separately. Different object-oriented programming languages support the packing in different
ways. For example, Java supports in the form of package, C in the form of header files etc.
Modules are program units that manage the visibility and accessibility of names. Following
purposes can be solved by modularity.
A module typically groups a set of class definitions and objects to implement some service
or abstraction.
A module is frequently a unit of division of responsibility within a programming team.
A module provides an independent naming environment that is separate from other
modules within the program.
Modules support team engineering by providing isolated name spaces.
Packaging involves the following three issues:
Information Hiding
Coherence of Entities
Constructing Physical Modules
Information Hiding: During analysis phase we are not concerned with information
hiding. So, visibilities of class members are not specified during analysis phase. It is done
during object design phase. In a class, data members and internal operations should be
hidden, so, they should be specified as private. External operations form the interface so they
should be specified as public.
The following design principles can be used to design classes:
A class should be given the responsibilities of performing the operations and proving
information contained in it to other classes.
Calling a method of that class should access attributes of other class.
Avoid traversing associations that are not connected to this class.
Define interfaces at the highest level possible.
External objects should be hidden. Defining interface classes could do this.
Avoid applying a method to the result of another class unless the result class is
already a supplier of methods to the caller class.
Coherence of Entities: Module, class, method etc. are entities. An entity is said to
coherent, if it is organized on a consistent plan and all its parts fit together toward a common
goal.
Policy is the making of context-dependent decisions while implementation is the
execution of fully specified algorithms. Policy involves making decisions, gathering
global information and interacting with the external agents. Policy and
implementation should be separated in different methods i.e. both should not be
combined into a single method.
A policy method does not have complex algorithms rather invokes various
implementation methods. It can contain I/O statements, conditional statements and
can access data stores.
An implementation method does exactly one operation, without making any decision,
assumption, default or deviation. All its information is supplied by arguments. These
methods do not contain any context-dependent decision so they are likely to be
reusable.
Constructing Physical Modules: Modules of analysis phase have changed as more classes
and associations have been added during object design phase. Now, the object designer has to
create modules with well-defined and minimal interfaces. The classes in a module should have
similar kinds of things in the system. There should be cohesiveness or unity of the purpose in a
module. So the classes, which are strongly associated, should be put into a single module.
Difference between SA/SD & OMT
It clearly marks the system boundaries across which System boundries can be easily
5 software procedures should communicate with real extending by adding new objects,
world. It is difficult to extend boundries. relationships.
9 Used when functions are more important than data. Used when data is more important
than functions.
Difficult to merge programming code organized about It better integrates data with
10 functions while database is organized around data. programming code as database is
organized around data.