CSC/ECE 517 Fall 2010/ch5 5c IC: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 31: Line 31:
public:
public:
   virtual int method1();
   virtual int method1();
   virtual void method3();
   virtual double method3();
}
}
</pre>
</pre>
Line 37: Line 37:
==Single vs Multiple Dispatch==
==Single vs Multiple Dispatch==


 
Dynamic dispatch comes in 2 types: [http://en.wikipedia.org/wiki/Dynamic_dispatch#Single_and_multiple_dispatch single and multiple dispatch].


==References==
==References==


[1] S. Milton, H.W. Schmidt, “Dynamic Dispatch in Object-Oriented Languages”, 2004.
[1] “Dynamic Dispatch in Object-Oriented Languages”, 2004.


[2] M. Muller, “Message Dispatch in Dynamically-Typed Object-Oriented Languages”, Master’s Thesis, University of New Mexico, 1995.
[2] M. Muller, “Message Dispatch in Dynamically-Typed Object-Oriented Languages”, Master’s Thesis, University of New Mexico, 1995.
[3] Dynamic dispatch, http://en.wikipedia.org/wiki/Dynamic_dispatch

Revision as of 18:59, 1 November 2010

Dynamic Dispatch

Introduction

Dynamic dispatch is an object-oriented programming concept that refers to the mapping of a method to an object's dynamic runtime type. It is common in many object-oriented languages. Languages such as Java and C++ use single dispatch, while only a few, such as CLOS, use multiple dispatch. Both types of dispatch will be discussed later.

Advantages

  • Flexibility
  • Extensibility

Disadvantages

  • Lookup overhead
  • Counter to safety and increased compile-time knowledge
  • Obstacle to optimization
  • Hinders compiler in determining exact type of objects

Example in C++

class A
{
  int aMember1;
public:
  virtual int method1();
  virtual void method2();
};

class B : public A
{
  int bMember1;
public:
  virtual int method1();
  virtual double method3();
}

Single vs Multiple Dispatch

Dynamic dispatch comes in 2 types: single and multiple dispatch.

References

[1] “Dynamic Dispatch in Object-Oriented Languages”, 2004.

[2] M. Muller, “Message Dispatch in Dynamically-Typed Object-Oriented Languages”, Master’s Thesis, University of New Mexico, 1995.

[3] Dynamic dispatch, http://en.wikipedia.org/wiki/Dynamic_dispatch