1 / 8

Polymorphism

Polymorphism. Encapsulation Inheritance Polymorphism (from the Greek meaning "having multiple forms"). Examples. Pledge: “I, (state your name), do solemnly swear….”

Download Presentation

Polymorphism

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Polymorphism • Encapsulation • Inheritance • Polymorphism (from the Greek meaning "having multiple forms")

  2. Examples • Pledge: “I, (state your name), do solemnly swear….” • UPE (Upsilon Pi Epsilon) pledge: "I ( state your name ), … having heard and understood ... the purposes and tenets of Upsilon Pi Epsilon ... do solemnly pledge, ... always to respect and promote ... the aims and ideals of this Society.” • Programing examples

  3. Virtual methods virtual void speak() {}; • Pure virtual method virtual void speak() = 0; • Override by a method in a derived class virtual void speak() override {}; • Compare to general method override • Both require identical signature • Static binding (binding to the type that the method is called) in general method override • vs, run-time binding in the virtual method case (derived class type’s method overrides at the time of instantiate).

  4. Which function to call? Object ClassA ClassB^ b=gcnew ClassB(); b->f(); ClassB ClassC C++: virtual method ClassD

  5. Abstract ref class • An incomplete definition of a ref class that has at least one pure virtual member method; • Cannot instantiate an object of it; • A derived class of it must implement the pure virtual function, (or, it becomes abstract)

  6. Applications

  7. C++ Example Object Employee Boss CommissionWorker PieceWorker HourlyWorker

  8. Summary • Although virtual functions of a base class are called within a framework, the actual functions to be called at run time are that of the actual class derived from the base class. • Only base classes are needed to define a framework. • Dynamic Binding versus Static Binding

More Related