Object Oriented Programming
Problem Description
“ …customers are allowed to have
different types of bank accounts,
deposit money, withdraw money and
t...
Procedural Approach
bool MakeDeposit(int accountNum,float amount);
float Withdraw(int accountNum,float amount);
struct Acc...
Procedural Approach cont’d
Focus is on procedures
All data is shared: no protection
More difficult to modify
Hard to manag...
Procedural vs. Object-Oriented
Procedural
Withdraw, deposit, transfer
Object Oriented
Customer, money, account
Mapping the world to software
Objects in the problem domain are mapped
to objects in software
Object Oriented
Data and operations are grouped together
Account
Withdraw
Deposit
Transfer
Interface:
Set of available ope...
Data Encapsulation
class Account {
public:
float withdraw();
void deposit(float amount);
private:
float balance;
);
Advantages of Encapsulation
Protection
Consistency
Allows change
Objects and Classes
Classes reflect concepts, objects reflect
instances that embody those concepts.
Daria Jane BrittanyJod...
Objects and Classes cont’d
A class captures the common
properties of the objects instantiated
from it
A class characterize...
Objects and Classes cont’d
Class BankAccount
Balance
InterestYTD
Owner
Account_number
Balance 500
InterestYTD
Owner
Accoun...
Objects as instances of Classes
The world conceptually consists of objects
Many objects can be said to be of the same
type...
Instantiation
An Object is instantiated from a Class
BankAccount myAccount;
myAccount = new BankAccount;
Objects and Classes
Class
 Visible in source
code
 The code is not
duplicated
Object
 Own copy of data
 Active in runn...
Classification
Mammal
Rodent Primate Cats
Reptile
Animal
Squirel RabbitMouse
Classification
Enjoy a variety of personal banking options from First American. The following
outlines a number of First A...
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...
Inheritance cont’d
A sub-class has all data members of its
base-class plus its own
A sub-class has all member functions of...
Abstraction
Management of complexity
Hierarchical classification:
is-a relationship: inheritance
has-a relationship: conta...
Polymorphism
One interface
Multiple implementations
Inheritance
Method overloading
What is a good class ?
A class abstracts objects
A class should be non-trivial in the
context of the program (has data
str...
Summary
What is Object Oriented Programming?
Object-oriented programming is a method of
implementation in which programs a...
Upcoming SlideShare
Loading in …5
×

Object Oriented Programming

260 views
166 views

Published on

Object Oriented Programming base Concepts

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
260
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Object Oriented Programming

  1. 1. Object Oriented Programming
  2. 2. Problem Description “ …customers are allowed to have different types of bank accounts, deposit money, withdraw money and transfer money between accounts”
  3. 3. Procedural Approach bool MakeDeposit(int accountNum,float amount); float Withdraw(int accountNum,float amount); struct Account { char *name; int accountNum; float balance; char accountType; };
  4. 4. Procedural Approach cont’d Focus is on procedures All data is shared: no protection More difficult to modify Hard to manage complexity
  5. 5. Procedural vs. Object-Oriented Procedural Withdraw, deposit, transfer Object Oriented Customer, money, account
  6. 6. Mapping the world to software Objects in the problem domain are mapped to objects in software
  7. 7. Object Oriented Data and operations are grouped together Account Withdraw Deposit Transfer Interface: Set of available operations
  8. 8. Data Encapsulation class Account { public: float withdraw(); void deposit(float amount); private: float balance; );
  9. 9. Advantages of Encapsulation Protection Consistency Allows change
  10. 10. Objects and Classes Classes reflect concepts, objects reflect instances that embody those concepts. Daria Jane BrittanyJodie girlclassobject
  11. 11. Objects and Classes cont’d A class captures the common properties of the objects instantiated from it A class characterizes the common behavior of all the objects that are its instances
  12. 12. Objects and Classes cont’d Class BankAccount Balance InterestYTD Owner Account_number Balance 500 InterestYTD Owner Account_number Balance 10,000 InterestYTD Owner Account_number Operations MakeDesposit Transfer WithDraw GetBalance
  13. 13. Objects as instances of Classes The world conceptually consists of objects Many 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
  14. 14. Instantiation An Object is instantiated from a Class BankAccount myAccount; myAccount = new BankAccount;
  15. 15. 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
  16. 16. Classification Mammal Rodent Primate Cats Reptile Animal Squirel RabbitMouse
  17. 17. Classification Enjoy a variety of personal banking options from First American. The following outlines a number of First American products. If you have any questions, please visit any First American Branch or contact us. Checking •Bank a lot without spending a lot: ValueFirst® Checking. •Few checks and prefer PC Banking or ATMs: Select Access. •Earn interest on checking dollars: First Interest Checking •You are 55 years or better: 55 & Better Silver •Premium checking features with higher interest rates than a personal checking account: First American Platinum Checking •Write less than 10 checks per month, or bank through an ATM: Budget Checking. •Younger than 24 years old and in school: Student Checking •Less than 20 transactions per month (excluding ATM, POS, and CheckCard): First Account •Make the most out of every dollar: Tailored Money Sweep
  18. 18. Classification Checking Account Value First Select Access First Interest Savings Account Account
  19. 19. 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
  20. 20. Inheritance cont’d A sub-class has all data members of its base-class plus its own A sub-class has all member functions of its base class (with changes) plus its own Inheritance is meant to implement sub- typing (don’t abuse it)
  21. 21. Abstraction Management of complexity Hierarchical classification: is-a relationship: inheritance has-a relationship: containment
  22. 22. Polymorphism One interface Multiple implementations Inheritance Method overloading
  23. 23. What is a good class ? A class abstracts objects A class should be non-trivial in the context of the program (has data structures and operations different from other classes)
  24. 24. Summary What is Object Oriented Programming? Object-oriented programming is a method of implementation in which programs are organized as cooperative collections of objects, each of which represents an instance of some class, and whose classes are all members of one or more hierarchy of classes united via inheritance relationships

×