Lecture 6b - OOAD Class Implementation
Lecture 6b - OOAD Class Implementation
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
assist in the execution of complex tasks. An example
might be a painting assistant (Pen, Canvas, Edit box)
for a graphics output device.
Implementing Class State
Properties are sometimes called variables or states.
To declare a property use the following syntax:
["public" | "private" | "protected" ] [
"final/const" ][ "static" ] data_type
var_name
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
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