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 :

#include <iostream>
#include <string>
using namespace std;

class MyClass{
	private :
		string first, second ;

		void set(string, string) ;
		string getFirst() ;
		string getSecond() ;

void MyClass::set(string x, string y){
	first = x ;
	second = y ;

string MyClass::getFirst(){
	return first;

string MyClass::getSecond(){
	return second;

int main() {

	MyClass objectA ;

	objectA.set("Hello, ","World!") ;

	cout << objectA.getFirst() << objectA.getSecond() << endl ;

	return 0;

Compile & Run:

Hello, World!

Leave a Reply