[go: up one dir, main page]

0% found this document useful (0 votes)
6 views67 pages

OOPS Fall 2024 Lecture 01 OOPIntro

The document is an introduction to a course on Object-Oriented Programming (OOP) taught by Dr. Muhammad Sadiq Amin, covering key concepts such as classes, objects, inheritance, and polymorphism. It includes details on the course structure, grading policy, class ethics, and required textbooks. The lecture emphasizes the importance of understanding OOP as a modeling technique that reflects real-world interactions through objects and their behaviors.

Uploaded by

muneebharoon261
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views67 pages

OOPS Fall 2024 Lecture 01 OOPIntro

The document is an introduction to a course on Object-Oriented Programming (OOP) taught by Dr. Muhammad Sadiq Amin, covering key concepts such as classes, objects, inheritance, and polymorphism. It includes details on the course structure, grading policy, class ethics, and required textbooks. The lecture emphasizes the importance of understanding OOP as a modeling technique that reflects real-world interactions through objects and their behaviors.

Uploaded by

muneebharoon261
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 67

CS-212

Introduction to Object-Oriented Programming

Lecture # 1
Object-Oriented Programming Concepts

Dr. Muhammad Sadiq Amin


Sadiq.amin@seecs.edu.pk
Introduction to Object-
Oriented Programming

Contents

Introduction

What this course is about?

Why should you take this course?

Course outline, textbook, grading policy etc.

Computers over time!

Key ideas in computing


Introduction
▪ About me …
▪ Postdoc in Federated Machine Learning
Gachon University, South Korea
▪ Ph.D. in Deep Learning & Computer vision
Tongmyong University, South Korea
▪ Research Interests
▪ Federated Machine Learning In HealthCare 5.0
▪ Deep learning & Computer Vision
▪ Emerging Computing (AI) Paradigms
▪ Contact
▪ Email: sadiq.amin@seecs.edu.pk
▪ Office
▪ A-217 SEECS floor 1.
▪ Office Hours: any time subject to my availability 
Students’ Introductions

▪ Let us get to know each other …


▪ Tell us about
▪ Your name
▪ Your subjects of interests!
▪ Your hobbies, inspiration and anything
else you are passionate about …
Acknowledgement
▪Content from following resources has been used in
these lectures CS304

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

● Objective of the course is to make


students familiar with the concepts of
object-oriented programming
● Concepts will be reinforced by their
implementation in C++

10
Contents

● Object-Orientation
● Objects and Classes
● Overloading
● Inheritance
● Polymorphism
● Generic Programming
● Exception Handling
● Introduction to Design Patterns
Books

●Beginning C++17 From Novice to


Professional, 5th edition
By Ivor Horton

●Ivor Horton's Beginning Visual C++


2008
By Ivor Horton

●Object-Oriented Software Engineering


By Jacobson, Christerson, Jonsson,
Object-Orientation (OO)
What is Object-Orientation?

● A technique for system modeling

● OO model consists of several


interacting objects

14
What is a Model?

● A model is an abstraction of
something

● Purpose is to understand the product


before developing it
Example Models

● 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

● People think in terms of objects


● (Procedural paradigm concentrate on
actions)
● OO models map to reality
● Therefore, OO models are
○easy to develop
○easy to understand
What is an Object?

An object is

● Something tangible (Ali, Car)

● Something that can be apprehended


intellectually (Time, Date)
… What is an Object?

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...)

OO languages (C++, Java, Python...)

Procedural languages (C, Fortran, COBOL...)

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

• What about C++?


Programming Paradigm

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

• 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
Object Oriented Programming (OOP)

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

• Almost any noun can be reasonably


represented as a software object in terms
of
– attributes (e.g., name, color and size)
– and behaviors (e.g., calculating, moving and
communicating).
Static Properties
Dynamic properties
Example (Person as an Object)

Attributes Behavior
age Walk()
Name Run()
address Teach(
)
Class

• Close your eyes for a minute and 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,
the definition does not exist

• 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
Class
Class
Class in OOP
Class
Concept of a “Class” 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”
Class
• A class is like a cookie cutter; it defines the
shape of objects
• Objects are like cookies; they are instances
of the class

Photograph courtesy of Guillaume Brialon on Flickr


Class

• The world is full of objects


• Many objects have always existed. New objects come to existence
and others cease to exist

• Mankind chose to classify objects i.e. name groups of objects based


on their attributes and their relationships
• For example:
– All things have been classed as either living things or non-living things
– Some living things are classed as vertebrae's and others as non-vertebrae’s
– A group of things like TVs, computers, phones etc are classified as electronics
– PCs, laptops, tablets and servers can be classified as computers as a subgroup of
electronics
• In the real world, only objects interact with
objects
Class

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. Objects may belong to a classification.
Class: Summary

A class defines the abstract characteristics of a


group of similar objects
• Attributes(fields or properties)
• Behaviors(methods or functions).
• A class is a user-defined type.
• A class is a blueprint or template to build
a specific type of object
• Every object is built from a class.
• Can be used to create objects: Variables of
the class type
What is a “Microwave”?
• An oven that uses
microwaves
to heat food

• It has a door

• It has a rotating trey inside

• It is a keypad based HMI

• It has a light in the oven

• Has a power rating


Object or Class?

These are two objects. Call them Microwave 1 and Microwave 2


You can call them My microwave and Ali’s microwave so on and so forth

Both belong to the CLASS microwave, which does not exist


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
OOP Approach

• Identify objects that the problem is concerned


with,
– e.g. Sports Application (Sportsman would be the
object),
• Produce a detailed design for each new
data type (Objects) including the operations
that can be performed on each object
• Express logic of your program in terms of
objects and kinds of operations they allow
OOP Approach
Online Booking: Tennis Court

• 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” is an Object-Oriented Programming Concept


C++ Class – Declaration
• To declare a class
– The class keyword is used
• The declaration is enclosed in braces {};
• The class definition ends with a semicolon
• Every piece of code inside the braces is
called ‘class body’
• The class body thus contains class members
C++ Class – Declaration

Class classname
{
………….
…………
…………….

};
C++ Class – Example
class Time {

private: Private:and Public: are


member-access specifiers.
int hour; // 0 - 23

int minute; // 0 - 59

int second; // 0 - 59 hour, minute, and second


are data members.
public:

Time();
setTime, printMilitary, and
void setTime( int, int, int ); printStandard are member functions.
Time is the constructor.
void printMilitary();

void printStandard();

};

You might also like