Page 181 - DCAP308_OBJECT_ORIENTED_ANALYSIS_AND_DESIGN
P. 181

Unit 14: Steps for Class Design




          Two-way Associations                                                                  Notes

          Many associations are traversed in both directions, although not usually with equal frequency.
          There are three approaches to their implementation:

               Implement as an attribute in one direction only and perform a search when a backward
               traversal is required. This approach is useful only if there is great disparity in traversal
               frequency and minimizing both the storage cost and update cost are important.

               Implement as attributes in both directions. It permits fast access, but if either attribute is
               updated then the other attribute must also be updated to keep the link consistent. This
               approach is useful if accesses outnumber updates.
               Implement as a distinct association object independent of either class. An association
               object is a set of pairs of associated objects stored in a single variable size object. An
               association object can be implemented using two dictionary object one for forward direction
               and other for reverse direction.

          Link Attributes

          Its implementation depends on multiplicity.

               If it is a one-one association, link attribute is stored in any one of the classes involved.
               If it is a many-one association, the link attribute can be stored as attributes of many object,
               since each “many object appears only once in the association.

               If it is a many-many association, the link attribute can’t be associated with either object;
               implement association as distinct class where each instance is one link and its attributes.

          14.1.8 Object Representation

          Implementing objects is mostly straight forward, but the designer must choose when to use
          primitive types in representing objects and when to combine groups of related objects. Classes
          can be defined in terms of other classes, but eventually everything must be implemented in
          terms of built-in-primitive data types, such as integer strings, and enumerated types.


                 Example: Consider the implementation of a social security number within an employee
          object. It can be implemented as an attribute or a separate class.
          Defining a new class is more flexible but often introduces unnecessary indirection. In a similar
          vein, the designer must often choose whether to combine groups of related objects.

          14.1.9 Organizing Class Design

          Programs consist of discrete physical units that can be edited, compiled, imported, or otherwise
          manipulated. In C and Fortran the units are source files; In Ada, it is packages. In object oriented
          languages, there are various degrees of packaging.

               !

             Caution In any large project, careful partitioning of an implementation into packages is
            important to permit different persons to cooperatively work on a program.







                                           LOVELY PROFESSIONAL UNIVERSITY                                   175
   176   177   178   179   180   181   182   183   184   185   186