Page 178 - DCAP308_OBJECT_ORIENTED_ANALYSIS_AND_DESIGN
P. 178

Object Oriented Analysis and Design




                    Notes          3.  Saving Derived Attributes to Avoid Recomputation: Data that is redundant because it can
                                       be derived from other data can be “cached” or store in its computed form to avoid the
                                       overhead of recomputing it. The class that contains the cached data must be updated if any
                                       of the objects that it depends on are changed.
                                       Derived attributes must be updated when base values change. There are three ways to
                                       recognise when an update is needed:
                                            Explicit update: Each attribute is defined in terms of one or more fundamental base
                                            objects. The 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 updated in bunches. Recompute all 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 incremental approach. Periodic
                                            recomputation is simpler than explicit update 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 all
                                            dependent values, but the calling code need not explicitly invoke the updates. It
                                            provides modularity.

                                   14.1.5 Implementation of Control

                                   The designer must refine the strategy for implementing the state – event models present in the
                                   dynamic model. As part of system design, you will have chosen a basic strategy for realizing
                                   dynamic model, during object design flesh out this strategy. There are three basic approaches to
                                   implementing the dynamic model:
                                   1.  State as Location within a Program: This is the traditional approach to representing
                                       control within a program. The location of control within a program implicitly defines the
                                       program state. Any finite state machine can be implemented as a program. Each state
                                       transition corresponds to an input statement. After input is read, the program branches
                                       depending on the input event received. Each input statement need to handle any input
                                       value that could be received at that point. In highly nested procedural code, low-level
                                       procedures must accept inputs that they may know nothing about and pass them up
                                       through many levels of procedure calls until some procedure is prepared to handle them.
                                       One technique of converting state diagram to code is as follows:
                                       (a)  Identify the main control path. Beginning with the initial state, identify a path
                                            through the diagram that corresponds to the normally expected sequence of events.
                                            Write the name of states along this path as a linear sequence of events. Write the
                                            names of states along this path as a linear sequence. This becomes a sequence of
                                            statements in the program.
                                       (b)  Identify alternate paths that branch off the main path and rejoin it later. These
                                            become conditional statements in the program.






          172                               LOVELY PROFESSIONAL UNIVERSITY
   173   174   175   176   177   178   179   180   181   182   183