Polymorphism Encapsulation Inheritance Polymorphism from the Greek meaning

  • Slides: 8
Download presentation
Polymorphism • Encapsulation • Inheritance • Polymorphism (from the Greek meaning "having multiple forms")

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

Examples • Pledge: “I, (state your name), do solemnly swear…. ” – UPE (Upsilon

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

• 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 Class. A Class. B^ b=gcnew Class. B(); b->f(); Class.

Which function to call? Object Class. A Class. B^ b=gcnew Class. B(); b->f(); Class. C C++: virtual method Class. D

 • Abstract ref class – An incomplete definition of a ref class that

• 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)

Applications

Applications

C++ Example Object Employee Boss Commission Worker Piece. Worker Hourly. Worker

C++ Example Object Employee Boss Commission Worker Piece. Worker Hourly. Worker

Summary • Although virtual functions of a base class are called within a framework,

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