answersLogoWhite

0


Best Answer

Polymorphism allows an object to assume different identities and behavior at run time. However, these objects should share similar features and inherit from a basic abstract object.

For example, we have a variety of graphics objects that are capable of drawing themselves, such as Circle, Triangle, Square, Rectangle and other shapes. A basic graphics object assumes the top of the inheritance hierarchy. Derived objects are the Circle, Triangle, Square, etc. The basic object supports a method called "Draw()" that allows it to draw itself on the screen. How this method is implemented is dependent on the actual object itself. Each derived object of the basic graphics object will have its unique implementation of Draw().


C++ has a feature called "dynamic binding" that implements polymorphism. Through dynamic binding, the appropriate virtual method() of Draw() is bound to the appropriate graphics object at run time.


A real world application such as a graphics editor maintains a container of objects that the user constructs at run time. Each of these objects is required to redraw itself on the screen when the screen refreshes and updates itself. Through polymorphism, the container of objects may iterate over itself and allow each object that it contains to dynamically draw itself at run time.


Sample code at compile time:


for (i=0; objects[i]; i++)
objects[i]->draw();


At run time, objects[0] = Circle, objects[1] = Square, objects[2] = Polygon, etc.
The behavior of the program at objects[i]->draw() is undefined until run time.


Other applications that utilize the feature of polymorphism includes:

  • providing to customers flight information from a variety of airlines, each airline abiding by a common set of API to access its flight information
  • providing to customers pricing information of parts from a variety of brands and manufacturers
  • providing to customers menu information from different restaurants in the area
  • any application that requires supplying to customers a common API (user interface) to access a multitude of databases (flight information, scheduling, food vendors, pricing information, etc.)
User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

The benefit of runtime polymorphism is that derived objects behave correctly even when you cannot know the exact type of the derivative in advance; all you know for certain is what kind of base class it is derived from. This ensures that even when other programmers derive new objects from the base class (which you cannopt possibly know about in advance), they will behave according to their actual type, simply by overriding the virtual methods provided by your base class. Thus you can invoke specialised methods from generic method calls, without the need for any expensive runtime type information routines (which should really only be required in debug code, if at all).

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are the applications of polymorphism in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Is overriding a dynamic polymorphism in c plus plus or not?

In C++, overriding and function, method, or operator is a different thing than (dynamic) polymorphism, so overriding a polymorphic method is almost entirely possible.


What are the concepts of object oriented programming in c plus plus?

The concepts of OOP in C++ are the same as for OOP in any other programming language: abstraction, encapsulation, inheritance and polymorphism.


Does c language support polymorphism?

C++ does.


What are the main features of OOP in c plus plus?

The main features of OOP are the same regardless of the language. They are: encapsulation; data hiding; inheritance; and polymorphism.


What are the various concepts of c plus plus?

1.Classes and Objects 2.Constructors and Destructors 3.Inheritance 4.Polymorphism 5.Dynamic Binding


Why is c plus plus regarded as being a hybrid language?

C++ is regarded as hybrid because it is both procedural and objected oriented. A pure c program can be compiled and run on a c++ platform. At the same time, c++ also provides object oriented features like classes, polymorphism, encapsulation, abtraction, etc.


Does C and C Plus Plus work properly in Vista?

This will depend upon whether the applications written in C or C++ have the correct runtime libraries on the target machine. The languages themselves make no difference.


What is the use of header file graphics in c plus plus programming?

It has no use in C++ itself, it is only useful in Borland Turbo C++. It provides generic graphics support for Borland Turbo C++ applications.


How can be different forms of polymorphism achieved?

Implicit Parametric PolymorphismSubtype PolymorphismExplicit Parametric Polymorphism


Why c plus plus is not complete object oriented language?

because c++ supports all the basic concepts of oop :1.objects,2.classes,3.data abstraction and encapsulation,4.inheritance,5.polymorphism,6.dynamic binding,5.message passing.


How does c plus plus endeavor to represent the object oriented paradigm?

C++ endeavours to represent the object oriented programming paradigm through the use of classes. The four main pillars of OOP are encapsulation, inheritance, polymorphism and abstraction, which C++ primarily achieves through the use of classes, class hierarchies, virtual methods and templates.


Which desktop application use c plus plus?

There are very few applications of any note that aren't written in C++ (or some combination of C++ and C). Even the Java virtual machine required to interpret Java programs is written in C++.