OOPS Fall 2024 Lecture 01 OOPIntro
OOPS Fall 2024 Lecture 01 OOPIntro
Lecture # 1
Object-Oriented Programming Concepts
Introduction
6
Grading Policy
▪ Quizzes
▪ 11.25% (15% of the lecture component)
▪ Assignments
▪ 3.75% (5% of the lecture component)
▪ Mid Semester Exam
▪ 22.5% (30% of the lecture component)
▪ ESE
▪ 37.5% (50% of the lecture component)
▪ Project
▪ 7.5% (30% of the lab component)
An updated GP has been uploaded on LMS.
Class Ethics
▪ Zero Tolerance for Plagiarism
▪ Never copy others’ assignment!
▪ If found, all copies will get 0 credit!
▪ Better fail now or you fail later in your life!
▪ Properly cite the resources used in assignments /
project
▪ Hard work
▪ Will always pay you off!
▪ Respect for all!
▪ If you have any problem, feel free to contact me!
Attendance and Attention!
▪ Mandatory 75% attendance!
▪ Policy will be strictly followed!
▪ Attendance will be marked at start for first lecture!
▪ Late commers will be marked as absent!
▪ For leave or consideration of attendance in case of
unavoidable circumstances, you will need approval
from UG coordinator for consideration!
▪ Attentiveness during lecture
▪ More important than attendance!
▪ Key to effective learning in semester-based system!
▪ Requires effort!
▪ Feel free to interrupt and ask questions and clarify
different points!
Contents
10
Contents
● Object-Orientation
● Objects and Classes
● Overloading
● Inheritance
● Polymorphism
● Generic Programming
● Exception Handling
● Introduction to Design Patterns
Books
14
What is a Model?
● A model is an abstraction of
something
● Highway maps
● Architectural models
● Mechanical models
Example - OO Model
Example - OO Model
lives-in
● Objects Ali House
○Ali
drives
○House
○Car
Car Tree
○Tree
● Interactions
○Ali lives in the house
○Ali drives the car
Object-Orientation Advantages
An object is
An object has
● State (attributes)
● Well-defined behaviour (operations)
● Unique identity
Example – Sadiq is a Tangible Object
● State (attributes)
○Name
○Age
● behaviour (operations)
○Walks
○Eats
● Identity
○His name
Example - Car is a Tangible Object
● State (attributes)
- Color
- Model
● behaviour (operations)
- Accelerate - Start Car
- Change Gear
● Identity
- Its registration number
What can be Intangible Objects
Example - Time is an Object apprehended
intellectually
● State (attributes)
- Hours - Seconds
- Minutes
● behaviour (operations)
- Set Hours - Set Seconds
- Set Minutes
● Identity
○ - Would have a unique ID in the model
Example - Date is an object apprehended
intellectually
● State (attributes)
- Year - Day
- Month
● behaviour (operations)
- Set Year - Set Day
- Set Month
● Identity
- Would have a unique ID in the model
Towards a higher level of abstraction
Declarative languages (Haskell, Prolog...)
Assembly languages
Binary code
There are always trade-offs
• High-level languages
– Simpler to write & understand
– More library support, data structures
• Low-level languages
– Closer to hardware
– More efficient
Programming Programming
provides paradigm is a
solution(program) to mental view of the
a real-world
problem and its
problem using
computational solution
models
Procedural Programming
f()
f()
Procedural Programming
f() x
f()
x
Procedural Programming
Procedural Programming
SPAGHETTI CODE
OOP Approach
f() x
f()
x
OOP Approach
Object Oriented Programming (OOP)
Paradigm
• “Object Oriented programming is an approach
of problem solving where all computations
are carried out using objects”
Object?
Object?
Object
Attributes & Behaviors in OOP
Attributes Behavior
age Walk()
Name Run()
address Teach(
)
Class
• 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)
• It has a door
• Court
• User
• Booking
Online Booking: Tennis Court
COLOR,
Attribute(Variables) SURFACE,
DIMENSION
Court
DO COURT BOOKING(),
Functionality(Functions) COURT CLEANING
Student Management System
Roll number
Attributes Name
Marks
Student
Curricular
performance
Behavior:
E
xtra curricular
performance
Basic Structure C and C++
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 classname
{
………….
…………
…………….
};
C++ Class – Example
class Time {
int minute; // 0 - 59
Time();
setTime, printMilitary, and
void setTime( int, int, int ); printStandard are member functions.
Time is the constructor.
void printMilitary();
void printStandard();
};