Dynamic Binding

Dinymic binding is a way to achieve polymorphism. It means we can declare an object with derivedclass type, and it can be viewed as an object with its base class type. The actual type of the object will be resolved at run time, so it is called dynamic binding. That introduce high flexibility to our codes.

ex.

void func(BaseClass &b)      // in C++, can use pointer or reference to achieve dynamic binding
{
    b.find();    
}

we can pass a reference of a derived class object as a parameter to the function. In C++, the function that we intend to achieve dynamic binding (in this case is find()) should be declared with "virtual" keyword in the base class, and must be implemented in derived class. Base class could declare it as a "pure virtual", then don't need to implement to it (This kind of base class is called abstract class).

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License