Upload
kimberly-lockyer
View
223
Download
0
Tags:
Embed Size (px)
Citation preview
Object Oriented Programming
Object Oriented
Data and operations are grouped together
AccountWithdraw
Deposit
Transfer
Interface:
Set of available operations
Data Encapsulation
class Account {
private float balance;
public float withdraw();
public void deposit(float amount);
}
Objects and Classes
Classes reflect concepts, objects reflect instances that embody those concepts.
Pooja Monica SrutiPriya
girlclassobject
Objects and Classes cont’d
A class captures the common properties of the objects instantiated from itA class characterizes the common behavior of all the objects that are its instances
Objects and Classes cont’dClass BankAccountBalanceInterestYTDOwnerAccount_number
Balance 500InterestYTDOwner Account_number
Balance 10,000InterestYTDOwner Account_number
Operations
MakeDesposit
Transfer
WithDraw
GetBalance
Objects as instances of Classes
The world conceptually consists of objectsMany objects can be said to be of the same type or class My bank account, your bank account, Bill
Gates’ bank account …
We call the object type a class
Objects and Classes
Class Visible in
source code The code is not
duplicated
Object Own copy of
data Active in
running program
Occupies memory
Has the set of operations given in the class
Classification
Checking Account
Value First Select Access First Interest
Savings Account
Account
Inheritance
A class which is a subtype of a more general class is said to be inherited from it.The sub-class inherits the base class’ data members and member functions
Inheritance cont’d
A sub-class has all data members of its base-class plus its ownA sub-class has all member functions of its base class (with changes) plus its ownInheritance is meant to implement sub-typing (don’t abuse it)
Abstraction
Management of complexityHierarchical classification:
is-a relationship: inheritancehas-a relationship: containment
Design an Object Oriented ATM
We will design and perform our own role play with objects
What classes do we need?– Display– Cash Dispenser– Card Reader– Bank Account– Others???
• What methods do we need? On which classes?– Make deposit– Make withdrawal– Balance Inquiry– Dispense cash– Others???????????