Skip to main content

Posts

Showing posts with the label derived

C++ Interface

In this tutorial we will discuss interfaces in C++ and why one would be of benefit.  First off, an interface serves as a means to have a commonality of usage for varies objects.  What I mean by that is that say you have a class representing a basketball and a class that represents a soccer ball, it is understood that both are used for playing but how they are played with is different.  That difference of how they are used for playing is where interfaces come in. An Interface provides a common way of using a class of type basketball and a class of type soccer ball without having will being able to refer to each different object(basketball or soccer ball) with the same interface. Okay okay, this is confusing so let us take a couple of examples. Without an interface, to have an object of basketball and soccer ball perform the same behavior, playing, you could do this: class BasketBall{ public:      void play(){           cout << "playing with basketball" << end