Page 12 - DCAP404 _Object Oriented Programming
P. 12

Unit 1: Review of Object-oriented Programming




          6.   Polymorphism: Polymorphism means the ability to take more than one form. An operation  Notes
               may exhibit different behavior in different instances.  The behavior depends upon  the
               types of the data used in the operation. For example considering the operator plus (+).
                         16 + 4 = 20
                         “xyz” + “sqr” = “xyzsqr”

                                            Figure  1.3














               The process of making an operator to exhibit different behavior at different instance is
               called operator overloading. Another example of polymorphisms is function overloading,
               where a single function can perform various different types of task.
          7.   Dynamic  Binding: Binding refers to the linking of a  procedure call to the  code to  be
               executed in response to the call. Dynamic binding means that the code associated with a
               given procedure call is not known until the time of call at run-time. This is associated with
               polymorphism and inheritance. A function call associated with a polymorphic reference
               depends on  the dynamic type of that reference.  For example in the  above figure,  by
               inheritance, every object will have this procedure. Its algorithm is, however, unique to
               each object so the procedure will be redefined in each class that defines the objects. At
               run-time, the code matching the object under reference will be called.



             Did u know? What is the difference between the static binding and dynamic binding?
             Static binding defines the properties of the variables at compile time. Therefore, they can’t
             be changed. In dynamic binding the properties of the variables are determined at runtime.

          8.   Message Passing: Message passing is another feature of object-oriented programming. An
               object-oriented program consists of a set of objects that communicate with each other. The
               concept of message passing makes it easier to talk about building systems that directly
               model or simulate their real-world counterparts.
               A message for an object is a request for execution of a procedure, and therefore will invoke
               a function in the receiving object that generates the desired result. Message passing involves
               specifying the name of the object, the name of the function (message) and the information
               to be sent.
                                            Figure  1.4

                                employee    salary      (name);




             Object                                                         information
                                            message




                                           LOVELY PROFESSIONAL UNIVERSITY                                    5
   7   8   9   10   11   12   13   14   15   16   17