CS212 - Object Oriented Programming
CS212 - Object Oriented Programming
Oriented
Programming
1
Outline
• Review
• Objects vs Classes
• Introduction to Java Basics
2
Need for OOP
Find green car
without
disturbing the
location of rest
of toys
A program in an
imperative language is a
list of instructions. Few
programmers can
comprehend a program
of more than a few
hundred statements
unless it is broken down
into smaller units
3
Need for OOP
Functions were
adopted as a way to
make programs more
comprehensible to
their human creators
Organized into
racks, easier
to find green
car
4
Unrestricted Access
5
Functions and Data
6
Problems with Procedural Programming
7
Problems with Procedural
Programming
8
Problems with Procedural
Programming
SPAGHETTI CODE
9
OOP: Real World Modeling
• In physical world we deal with objects such as
cars and people.
10
Need for OOP
OOP was developed to overcome the limitations
of the traditional programming languages
• As the programs get larger in
procedural programming it becomes
more complex to:
– Understand the logic
– Identify bugs
– Change programs
– Maintain
11
OOP Approach
Identify objects :
Accounting application :
Account, Transaction, Account Holder etc.
12
OOP Approach
• The fundamental idea behind object-oriented
language is to combine into a single unit
both
– data and
– the functions that operate on that data.
13
OOP Approach
14
Example:
Regn_no
Emp_id
Gpa
Salary
batch
Grade_Assignment()
Issue_Fee_Challan()
Submit_Assignment()
Share_Timetable()
Attend_Classes()
Prepare_Lecture_Slides()
Appear_In_Exam()
Approve_Scholarship()
15
Spaghetti Code
16
OOP
Student
Regn_no Gpa
Batch
ACB
Submit_Assignment() Share_Timetable()
Attend_Classes()
Appear_In_Exam()
Accounts
Branch
Faculty Issue_Fee_Challan()
Approve_Scholarship()
Emp_id
Salary
Grade_Assignment()
Prepare_Lecture_Slides()
17
CLASSES & OBJECTS
18
Classification
19
Classification
20
Class
• Think about what do you understand when you hear the word
“chair”
• However, if you look around the room, there are several chairs are
in the room, and each chair is an object. Each of these objects is an
example of that thing called the Chair (class)
}
Java Class – Body
• Every piece of code inside the braces is
called ‘class body’
• The class body thus contains:
Java Class – Body
• Every piece of code inside the braces is
called ‘class body’
• The class body thus contains class members
Class vs Object in OOP
29
QUESTIONS!
30