Page 179 - DCAP308_OBJECT_ORIENTED_ANALYSIS_AND_DESIGN
P. 179
Unit 14: Steps for Class Design
(c) Identify backward paths that branch off the main loop and rejoin it earlier. These Notes
become loops in program. If multiple backward paths that do not cross, they become
nested loops. Backward paths that cross do not nest and can be implemented with
goto if all else fails, but these are rare.
(d) The status and transitions that remain correspond to exception conditions. They can
be handled using error subroutines, exception handling supported by the language,
or setting and testing of status flags. In the case of exception handling, use goto
statements.
2. State machine engine: The most direct approach to control is to have some way of explicitly
representing and executing state machine.
Example: State machine engine class helps execute state machine represented by a table
of transitions and actions provided by the application.
Each object instance would contain its own independent state variables but would call on
the state engine to determine next state and action. This approach allows you to quickly
progress from analysis model to skeleton prototype of the system by defining classes
from object model state machine and from dynamic model and creating “stubs” of action
routines. A stub is a minimal definition of function/subroutine without any internal code.
Thus if each stub prints out its name, technique allows you to execute skeleton application
to verify that basic flow of control is correct. This technique is not so difficult.
3. Control as Concurrent Tasks: An object can be implemented as task in programming
language/operating system. It preserves inherent concurrency of real objects. Events are
implemented as inter task calls using facilities of language/operating system. Concurrent
C++/Concurrent Pascal support concurrency. Major Object Oriented languages do not
support concurrency.
14.1.6 Adjustment of Inheritance
The definitions of classes and operations can often be adjusted to increase the amount of
inheritance.
The designer should:
1. Rearrange classes and operations: Sometimes the same operation is defined across several
classes and can easily be inherited from a common ancestor, but more often operations in
different classes are similar but not identical. By slightly modifying the definitions of the
operations or the classes, the operations can often be made to match so that they can be
covered by a single inherited operation. Before inheritance can be used, each operation
must have the same interface and the types of arguments and results. If the signatures
match, then the operations must be examined to see if they have the same semantics. The
following kinds of adjustments can be used to increase the chance of inheritance.
Some operations may have fewer arguments than others. The missing arguments
can be added but ignored.
Some operations may have few arguments because they are special cases of more
general arguments. Implement the special operations by calling the general operation
with appropriate parameter values.
Similar attributes in different classes may have different names. Give the attributes
the same name and move them to a common ancestor class. These operations that
access the attributes will match better.
LOVELY PROFESSIONAL UNIVERSITY 173