Monday, September 8, 2008

REALIZATION

In object oriented programming (OOPS), REALIZATION is a kind of relationship between two classes where one class provides the template for all the functions to be used , while the other class actually provides the functionalities to the defined functions.

The class providing the template is known as “Supplier” class while the class providing the implementation is called as “Consumer” class.

This type of relationship is used in Interface based architecture or template based architecture.

In the given example the class “Account” is an interface class and it gets implemented by the class
“SavingAccount”.

In UML the same thing is denoted as









#include "stdafx.h"


// Supplier class or Interface class
class Account
{
private:


protected:
float fPrincipal, fInterest, fTime, fRate;
public:
virtual void SetPrincipal(float fPrincipal)=0;
virtual void SetTime(float fTime)=0;
virtual void SetRate(float fRate)=0;
virtual void CalculateInterest()=0;
virtual void ShowInterest()=0;
};


// Consumer class or Implementor class
class SavingAccount : public Account
{
private:


protected:

public:
void SetPrincipal(float fPrincipal);
void SetTime(float fTime);
void SetRate(float fRate);
void CalculateInterest();
void ShowInterest();

};

void SavingAccount::SetPrincipal(float fPrincipal)
{
this->fPrincipal = fPrincipal;
}

void SavingAccount::SetTime(float fTime)
{
this->fTime = fTime;
}

void SavingAccount::SetRate(float fRate)
{
this->fRate = fRate;
}

void SavingAccount::CalculateInterest()
{
fInterest = (fPrincipal * fTime * fRate ) / 100;
}

void SavingAccount::ShowInterest()
{
printf("Intereset is - %f", fInterest);
}

int main(int argc, char* argv[])
{
SavingAccount objSavAcc;

objSavAcc.SetPrincipal(10000);
objSavAcc.SetRate(5.9);
objSavAcc.SetTime(2);
objSavAcc.ShowInterest();

return 0;
}