80 likes | 198 Views
Polymorphism. Encapsulation Inheritance Polymorphism (from the Greek meaning "having multiple forms"). Examples. Pledge: “I, (state your name), do solemnly swear….”
E N D
Polymorphism • Encapsulation • Inheritance • Polymorphism (from the Greek meaning "having multiple forms")
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
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).
Which function to call? Object ClassA ClassB^ b=gcnew ClassB(); b->f(); ClassB ClassC C++: virtual method ClassD
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)
C++ Example Object Employee Boss CommissionWorker PieceWorker HourlyWorker
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