Professional Documents
Culture Documents
Lecture 6b - OOAD Class Implementation
Lecture 6b - OOAD Class Implementation
Lecture 6b - OOAD Class Implementation
IMPLEMENTING CLASS
DIAGRAM IN C++ AND JAVA
Classes encapsulation and Instantiation
2
Account
getBalance
getInterest
Deposit money
Withdraw money
Bank account - Data Areas
6
.
Revision of Account
7
Account
double getBalance();
double getInterest();
deposit(double amount);
withdraw(double amount);
Varieties of Classes
8
Data Managers
Classes whose principal responsibility is to maintain
data values.
Account - maintains balance and account number
information.
Data Sinks and Sources
Objects that interface to data generators or
views.
Facilitator and Helper Classes
Classes that maintain little or no state information, but
Accessor;
Mutator
Constructors
include<iostream>
using namespace std;
class Demo{
public:
Demo();
~Demo();
};
Demo::Dem()
{
cout<<"Welcome. This is OOP"<<endl;
}
Example 1
Demo::~Demo()
{
cout<<"Good bye\n";
}
int main(){
Demo Greetings;
cout<<"Demostrates a constructor and
displays goodbye when";
cout<<" a destructor is called\n";
return 0;
}
C++ Example 2
#include<iostream>
using namespace std;
class Employee {
private:
int idNum;
double salary;
public:
Employee()
{
int idNum = 120;
double salary=100.0;
Example 2
cout<<"Id number "<<idNum<<"\tSalary is
"<<salary<<endl;
cout<<endl;
}
~Employee ()//object is cleared from memory
{
cout<<"Object cleared from RAM\n";
}
};
void main(){
Employee workers;//constructor called
}
Interface and Implementation
implementation part
Interface descriptions and implementation bodies
cout<<fixed<<showpoint<<setprecision(2);
cout<<"Enter the amount of sale "<<endl;
cin>>amount;
cashier.calSales(amount);
cout<<"The total sale is
"<<cashier.getTotal()<<endl;
return 0;
}
Interface and implementation in Java