Interface Vs Implementation

This concept focuses upon separating what an object does from how it does it.

 

This concept goes hand in hand with encapsulation, data hiding and abstraction in providing the foundations for OOP.

 

Specifically, Interface is the public methods of a class that control how it behaves. Whereas implementation is the actual workings of how it behaves.

 

For instance, slightly modifying the previous example, the class now simply declares its interfaces within the class declaration.

 

The implementation has been defined outside of the class declaration, but is associated via the scope resolution operator ::

 

Thus, this class's interface can be seen on lines 10, 11 and 12, and their according implementations on lines 15, 20 and 24 :

Compile & Run:

Hello, World!

Leave a Reply