Page 37 - DCAP308_OBJECT_ORIENTED_ANALYSIS_AND_DESIGN
P. 37

Unit 3: Class Modelling




          Generalization is the relationship between a class, and it defines a hierarchy of abstraction in  Notes
          which subclasses (one or more) inherit from one or more superclasses. Generalization and
          inheritance are transitive across a subjective number of levels in the hierarchy. Generalization
          is an “is-a-kind of” relationship. For instance, Saving Account is a kind of Account; PG student is
          kind of Student, etc.
          The notation for generalization is a triangle connecting a super class to its subclasses. The
          superclass is connected by a line to the top of the triangle. The subclasses are connected by lines
          to a horizontal bar attached to the base of the triangle.

               !
             Caution Generalization is a very useful construct for both abstract modeling and
             implementation.


                 Example: A generalization of account class is shown in Figure 3.8.
                               Figure 3.8: Generalization of Account Class


                                               Account






                     Saving Account                            Current Account


          Source:  http://vedyadhara.ignou.ac.in/wiki/images/a/aa/B1U1mcs-032.pdf

          3.3.2  Inheritance

          Inheritance is taken in the sense of code reuse within the object oriented development. During
          modeling, we look at the resulting classes, and try to group similar classes together so that code
          reuse can be enforced. Generalization, specialization, and inheritance have very close association.
          Generalization is used to refer to the relationship among classes, and inheritance is used for
          sharing attributes and operations using the generalization relationship.




             Notes In respect of inheritance, generalization and specialization are two phases of a coin
            in the sense that if a subclass is seen from a superclass the subclass is seen as a specialized
            version of superclass and in, reverse, a superclass looks like general form of subclass.

          During inheritance, a subclass may override a superclass feature by defining that feature with
          the same name. The overriding features (the subclass feature with the same names of superclass
          features) refine and replace the overridden feature (the superclass feature).


                 Example:  Let us look at the diagram given in Figure 3.9. In this diagram, Circle, Triangle,
          and Square classes are inherited from Shape class. This is a case of single inheritance because
          here, one class inherits from only one class.






                                           LOVELY PROFESSIONAL UNIVERSITY                                   31
   32   33   34   35   36   37   38   39   40   41   42