0% found this document useful (0 votes)
61 views

CS212 - Object Oriented Programming

The document provides an introduction to object-oriented programming concepts. It discusses the need for OOP to overcome limitations of procedural programming. Some key points made are: 1) OOP was developed to model real-world objects that have both attributes and behaviors. This is unlike procedural programming which treats data and functions separately. 2) A class defines the type of an object and describes its attributes and behaviors. Objects are actual instances of a class in memory. 3) The document uses examples like students and faculty to illustrate class definitions and object instantiation from classes. It explains how OOP provides a better way to structure complex programs compared to procedural approaches.

Uploaded by

Muneeb Asif
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

CS212 - Object Oriented Programming

The document provides an introduction to object-oriented programming concepts. It discusses the need for OOP to overcome limitations of procedural programming. Some key points made are: 1) OOP was developed to model real-world objects that have both attributes and behaviors. This is unlike procedural programming which treats data and functions separately. 2) A class defines the type of an object and describes its attributes and behaviors. Objects are actual instances of a class in memory. 3) The document uses examples like students and faculty to illustrate class definitions and object instantiation from classes. It explains how OOP provides a better way to structure complex programs compared to procedural approaches.

Uploaded by

Muneeb Asif
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

CS212 – Object

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

• Major problems with procedural programming


– Unrestricted access of functions to global data
– No coupling among functions and data, the basis of
procedural programming, provide a poor model of the
real world.

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.

• Such kind of objects are not like the data and


are not like the functions

• Complex real world objects have both


attributes and behavior

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.

Express logic of your program in terms of objects


and kinds of operations they allow.

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.

• Such a unit is called an object

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

Classify these Objects:


• Merc, Audi , BMW,…
• Messi, Ronaldo,Neymar,…
• Pen, pencil, rubber,…

19
Classification

20
Class
• Think about what do you understand when you hear the word
“chair”

• We know that chairs have properties like :


– seating capacities,
– back,
– number legs
– shape
– color
– a degree of softness and so on so forth
Example (Chair as an Object)
• The idea of the chair allows you to recognize a 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)

• A class is a description of a kind of thing.


• An object is an actual thing
What is classification?
• The world is full of objects

Remember: A CLASS is ONLY a definition. It


describes a set of qualifiers that describe what the
objects that belong to that class look like

The things that are tangible and exist are


the Objects.
Class
• A class is a programmer-defined data type. It consists
of data members and functions which operate on
that data.
– Data Members define Object attributes
– Member Functions define Object Behavior

• “Class” is an Object-Oriented Programming Concept


Java Class – Declaration
• To declare a class
– The class keyword is used
• The declaration is followed by braces {}
• Every piece of code inside the braces is called
‘class body’
• The class body thus contains class members
Java Class – Declaration
class ClassName
{
………….
…………
…………….

}
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

A key aspect of Object Oriented Programming


is the use of Classes
• A class is a specification/model of an object
• You can “think of a class as a concept” and
an object as “Realization of that concept”

29
QUESTIONS!

30

You might also like