Polymorphism

While programming in C, we get close to the system. 
In this course, we'll use C to examine how building-blocks are built and gain a deeper understanding of polymorphism. Let's explore its internals.

Polymorphism

It means 'occurring in different forms'. It is an indispensable aspect of modern software production. For example, doctors want different forms of imaging for different parts of the body; developers want different forms of environments for testing and production -  Code often needs to run in different contexts. And these contexts keep growing over time.

There are many ways to realize these 'different forms'. Let's look at a trivial way, which doesn't use polymorphism.

Suppose we had a row of different heavy artillery machines. They look alike, but are made by different companies. Each company has provided its own function to fire the projectile. For example, the Howitzer equipment has a function called 'howitzer_v1_fire', while Dhanush provides a function called 'dhanush_fire' and so on. These functions accept an equipment-identifier to distinguish the one to be fired.

Our job is to program them to fire in quick succession.
U.S. Army photo by Pfc. Dasol Choi, 1st Armored Brigade Combat Team Public Affairs, 1st Cav. Div.

To do this, I wrote the following function:
void synchronized_fire() {
  howitzer_v1_fire(GUN_ID1);
  dhanush_fire(GUN_ID2);
  bofors_v2_fire(GUN_ID3);
  howitzer_v2_fire(GUN_ID4);
  dhanush_fire(GUN_ID5);
}

What's wrong in writing the function this way?

Feel free to comment below. The topic is continued here

Comments

  1. Is there really a problem? The function works, right?

    ReplyDelete
    Replies
    1. Yes, but think about deployment. Every new sequence of guns will require a new program. So if there are deployments along the border and each has a different set of guns, each of them will require a different version of this program. Very soon, the number of versions will become huge.
      Adding a gun from a new manufacturer will require a re-release of all these versions, increasing the effort and cost involved in maintenance.

      Delete
    2. "Let's look at a trivial way, which doesn't use polymorphism" - what do you mean by these lines? Can you explain these lines?

      Delete
  2. Wonderful article, Which you have shared here about the Polymorphism. Your article is very informative and I liked your way to share your knowledge in this post. If anyone interested to join the Best C++ With Data Structures Course In Delhi, codingbytes is good for you.

    ReplyDelete
  3. This is what we want. You have pointed out some great info here. Register for best selenium course online now

    ReplyDelete
  4. Anvsoft Syncios 8.7.4 Crack can be an IOS manager, report moving, conversation, the file coping with, iPhone, iPod, i-pad, PC, Touch.Syncios crack

    ReplyDelete
  5. AVS Video Converter 12.4.2 Crack is a free program that efficient, easy-to-use tool that converts videos between the most popular formats .Avs Video Compressor

    ReplyDelete

Post a Comment

Popular posts from this blog

Relationships in a Relational Database

Data Schema and Blobs

Power On!