SlideShare a Scribd company logo
Women University of Azad Jammu and Kashmir Bagh
Department of Computer Sciences and Information Technology, Women University of Azad Jammu and Kashmir Bagh
www.wuajk.edu.pk
Object Oriented Programming
CS-3201
Dr. Anees Qumar Abbasi
aneesabbasi.wuajk@gmail.com
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Course Objective
The course aims to focus on object-oriented concepts, analysis, and
software development.
This course provides in-depth coverage of object-oriented
programming principles and techniques using C++, Understanding,
and fundamentals (principles) of object-oriented programming:
abstraction, encapsulation, polymorphism, and inheritance.
Strong skills in Object Oriented programming will help students to
boost their skills in software development
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Background
• It is expected that you have experience of
writing and understanding programs with C.
• It is also expected that students will have the
knowledge of Functions, structures and
Pointers.
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Course Outline
1. Introduction to OOP:
1. What is OOP and its benefits?
2. Basic concepts: objects, classes, encapsulation,
inheritance, and polymorphism.
3. Comparison between procedural programming
and OOP.
2. Classes and Objects:
1. Defining classes and objects.
2. Attributes and methods.
3. Constructors and destructors.
4. Access modifiers: public, private, and
protected.
3. Inheritance and Polymorphism:
1. Inheritance: extending classes, base class, and
derived class.
2. Method overriding and method overloading.
3. Polymorphism: compile-time and runtime
polymorphism.
4. Encapsulation and Abstraction:
1. Encapsulation: data hiding and
accessors/mutators.
2. Abstraction: abstract classes and interfaces.
3. Difference between encapsulation and
abstraction.
5. Association, Aggregation, and Composition:
1. Relationships between classes.
2. Association: simple and directional
relationship.
3. Aggregation: "has-a" relationship.
4. Composition: strong ownership relationship.
6. Exception Handling:
1. Handling runtime errors and exceptions.
2. Try-catch blocks and exception propagation.
7. Additional Topics (time permitting):
1. Polymorphism with interfaces.
2. Abstract classes vs. interfaces.
3. Method overriding and final classes/methods.
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Course Material
Main Material
Will be available through slides and Notes
Reference Books:
Object Oriented Programming in C++, Fourth
Edition By RoberLafore,
C How to Program, Sixth Edition Dietal & Dietal
Object Oriented Programming in C++, IT Series
www.codeproject.com
www.codeguru.com
www.howstuffworks.com
www.whatis.com
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Course Communication
Email:
aneesabbasi.wuajk@gmail.com
Piazza:
Piazza is a cloud-based social learning platform, which helps teachers
manage classes, create student groups, post announcements, share files
and lecture videos and participate in class discussions with students.
Please Join:
https://piazza.com/women_university_of_ajk_bagh/spring2023/cs3201
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
How to get the goals?
Read and remember
Read the books, remember the language
Think
Think in objects, think in classes
Practice
Do as many coding as possible and make them running
Ask
Email me questions
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Programming is the process of creating computer
programs by writing instructions in a programming
language to solve specific problems or automate tasks.
It is a fundamental skill in the field of computer science
and plays a crucial role in the development of software and
technology.
Programming is like writing.
If you can write a demonstration, you can make a program
So, programming is also easy.
Programming
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Programming
But, actually, programming is not so easy, because a real
good program is not easily programmed.
It needs the programmers’ lots of wisdom, lots of
knowledge about programming, and lots of experience.
It is like writing, to be a good writer needs lots of
experience and lots of knowledge about the world.
Learning and practice are necessary.
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Programming Techniques
The evolution of programming techniques is:
to make programming languages more
expressive
to develop complex systems more easily
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Programming Techniques
Unstructured Programming
Procedural Programming
Modular & Structural Programming
Object-Oriented Programming
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Unstructured Programming
Unstructured programming is a historical
programming technique characterized by a
lack of high-level organization and control
structures. It heavily relies on sequential
execution.
Usually, people start learning programming by
writing small and simple programs consisting
only of one main program.
Here ``main program'' stands for a sequence
of commands or statements which modify data
that is global throughout the whole program.
Main Program
Data
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Drawbacks
Readability and Maintainability
Code Duplication
Spaghetti Code
Limited Abstraction
Limited Reusability
Difficulty in Error Handling
Lack of Scalability
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Procedural Programming
Procedural programming emphasizes the use
of procedures or functions to structure code.
It focuses on step-by-step procedure
execution, with a main program coordinating
the execution of smaller procedures.
With procedural programming, you are able to
combine sequences of calling statements into
one single place.
A procedure call is used to invoke the
procedure. After the sequence is processed,
the flow of control proceeds right after the
position where the call was made.
Main
Program
Procedure
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Procedures
A procedure is a named sequence of instructions or a subroutine
that performs a specific task. It is a reusable block of code that
can be called or invoked from different parts of a program.
Procedures help in organizing code, promoting code reuse, and
improving readability and maintainability.
With parameters and sub-procedures (procedures of procedures),
programs can now be written more structured and error-free.
For example, if a procedure is correct, every time it is used it
produces correct results.
Consequently, in cases of errors you can narrow your search to
those places which are not proven to be correct.
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Procedural Program view
Main Program
Data
Procedure1
Procedure2 Procedure3
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Modular Programming
Emphasizes breaking down a program into independent and self-
contained modules or components.
Each module represents a specific functionality or task and can be
developed and maintained separately from other modules.
These modules interact with each other through well-defined
interfaces, promoting code reusability, maintainability, and
scalability.
With modular programming, procedures of a common functionality
are grouped together into separate modules.
A program therefore no longer consists of only one single part. It is
now divided into several smaller parts which interact through
procedure calls and which form the whole program.
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Main Program(Also a module)
Data
Data Data1
Module2
+
Data Data2
Module1
+
Data Data1
Procedure1
Procedure2
The main program coordinates calls to procedures in separate modules and hands over
appropriate data as parameters.
Procedure3
Modular Program view
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Modular Programming
Each module can have its own data. This allows each
module to manage an internal state which is modified by
calls to procedures of this module.
Each module has its own special functionalities that
supports the implementation of the whole program.
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Structural Programming
A subset of procedural programming that enforces a logical
structure on the program being written to make it more efficient
and easier to understand and modify.
It aims to improve the clarity, readability, and maintainability of
code by enforcing a structured control flow.
It emphasizes the use of control structures, such as loops and
conditionals, to provide clear and organized program logic.
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Problems with Structured Programming
Many Functions access the same data, change in data may
require rewriting of all functions. It makes program difficult to
modify.
It makes a program structure difficult to conceptualize.
Arrangement of separate data and functions does a poor job of
modeling things in real world.
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Object-Oriented Programming
OOP is a technique in which programs are written on the basis of
objects. An object is collection of data and functions.
The fundamental idea behind object oriented programming is to
combine both data and functions into a single unit. Such a unit is called
object.
Object is derived from abstract data type.
Object-oriented programming has a web of interacting objects, each
house-keeping its own state.
Objects of a program interact by sending messages to each other.
OOP is based on real world modeling.
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Object1
Data1+Procedures1
Data Data1 Object3
Data3 + Procedures3
Object2
Data2 + Procedures2
Object4
Data4 + Procedures4
Object-Oriented Programming – Program View
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Object-Oriented Programming
In object-oriented programming , instead of calling a procedure
which we must provide with the correct handle, we would directly
send a message to the object in questions.
Roughly speaking, each object implements its own module.
Each object is responsible to initialize and destroy itself correctly.
Consequently, there is no longer the need to explicitly call a
creation or termination procedure.
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
What is an Object?
Objects are tangible entities that exhibit some well-defined
behavior (Almost everything is an object).
Object is a fundamental building block that represents a particular
instance of a class.
It is a runtime entity that combines data/fields (attributes) and behavior
(methods) into a single entity.
An object has:
Properties/State (attributes)
Functions/ Well-defined behaviour (operations)
Unique identity
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Example – Ali is a Tangible Object
► State (attributes/properties/fields):
Name
Age
Height
Color
► Behaviour (operations/methods):
Walks
Eats
Sleep
► Identity:
His name
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Example – Car is a Tangible Object
► State (attributes/properties/fields):
- Color
- Model
► Behaviour (operations/methods):
- Accelerate
- Start Car
- Change Gear
► Identity:
- Its registration number
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Example – Time is an Object:
Apprehended Intellectually
► State (attributes/properties/fields):
► Hours
► Seconds
► Minutes
► Behaviour (operations/methods):
► Set Hours
► Set Seconds
► Set Minutes
► Identity
► Would have a unique ID in the model
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Class
► A Collection of objects with same properties and functions is
known as class.
► A class is used to define the characteristics of the objects.
Example:
Person is a class that can be used to define characteristics and
functions of a person.
It can be used to create many objects of type Person, such as Ali,
Imran etc.
All objects of Person class will have same properties and functions.
However, the values of each object can be different.
Each object is known as instance of its class.
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Some Facts about OOP
Everything is an object.
Objects perform computation by making requests of each other
through the passing of messages .
Every object has it's own memory, which consists of other
objects.
Every object is an instance of a class. A class groups similar
objects.
The class is the repository for behavior associated with an
object
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Features of OOP
Objects
OOP provides the facility of programming based in objects. Object is an
entity that consists of data and functions.
Classes
Classes are designed to create objects. OOP provides facility to design
classes.
Real-world Modeling
OOP is based on real-world modeling. As in the real world, things have
properties and working capabilities. Similalrly, objects have data and
functions. Data represents properties and functions represents working of
objects.
Reusability
OOP provides ways to reuse data and code (inheritance).
Information Hiding
OOP allows the programmer to hide important data from the user
(Encapsulation)
Polymorphism
Polymorphism is an ability of an object to behave in multiple ways.
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Object Oriented Languages
C++
JAVA
C# (C Sharp)
Python
Many other
Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Implementation Language: C++
C++ is an Object Oriented language.
It was developed in 1985 at Bell Laboratories.
It is an improved version of C.
It was originally named “C with classes”.
It is very powerful language and is used to develop a variety of
programs.
It is very much compatible with C.

More Related Content

PDF
Adv & disadv of oo ps
PPTX
Lecture No.1.pptx
PPTX
OOP - Benefits and advantages of OOP
PPTX
Unit 1 OOSE
PPTX
Introduction to object oriented language
DOC
Preliminry report
PPTX
BCSE01T1003 Unit 1 Lec 1- Introduction to OOP.pptx
PPTX
BCSE01T1003 Unit 1 Lec 1- Introduction to OOP.pptx
Adv & disadv of oo ps
Lecture No.1.pptx
OOP - Benefits and advantages of OOP
Unit 1 OOSE
Introduction to object oriented language
Preliminry report
BCSE01T1003 Unit 1 Lec 1- Introduction to OOP.pptx
BCSE01T1003 Unit 1 Lec 1- Introduction to OOP.pptx

Similar to Lec_1,2_OOP_(Introduction).pdf (20)

PPTX
MODULE-I(CSE3005) Vit bhopal presentation.pptx
PDF
Oop basic overview
PDF
ALX SE Guide For The Software Engineering PATH
PDF
1.1 Introduction to procedural, modular, object-oriented and generic programm...
DOCX
What Skills Do You Gain From A Post Graduate Program In Devops?
PPTX
Cpe orientation
PPTX
Project based learning methodologies for Embedded Systems and Intelligent Sys...
DOCX
Basic Computer.docx
PPTX
OOPM - Introduction.pptx
PDF
Download full ebook of Basics Of Programming Dg Junior instant download pdf
DOCX
Bright copy
PPTX
Structured programming & Programming methodologies.pptx
PPTX
PCCF UNIT 2 CLASS.pptx
DOCX
Office automation system report
DOCX
Office automation system report
DOC
PPTX
BSC Software & Software engineering-UNIT-IV
PDF
Evaluvation of Applying Knowledge Management System Architecture in Software ...
DOCX
PPTX
SE&PM-MODULE-1 2.pptx Software engineering
MODULE-I(CSE3005) Vit bhopal presentation.pptx
Oop basic overview
ALX SE Guide For The Software Engineering PATH
1.1 Introduction to procedural, modular, object-oriented and generic programm...
What Skills Do You Gain From A Post Graduate Program In Devops?
Cpe orientation
Project based learning methodologies for Embedded Systems and Intelligent Sys...
Basic Computer.docx
OOPM - Introduction.pptx
Download full ebook of Basics Of Programming Dg Junior instant download pdf
Bright copy
Structured programming & Programming methodologies.pptx
PCCF UNIT 2 CLASS.pptx
Office automation system report
Office automation system report
BSC Software & Software engineering-UNIT-IV
Evaluvation of Applying Knowledge Management System Architecture in Software ...
SE&PM-MODULE-1 2.pptx Software engineering
Ad

More from AneesAbbasi14 (10)

PPTX
Goal Setting UPDATED.pptx
PDF
Lec_15_OOP_ObjectsAsParametersFriendClasses.pdf
PDF
lecture-2021inheritance-160705095417.pdf
PDF
lecture-18staticdatamember-160705095116.pdf
PPTX
lec09_ransac.pptx
PPTX
lec07_transformations.pptx
PPTX
02-07-20_Anees.pptx
PPTX
Yasir Presentation.pptx
PPTX
Lec5_OOP.pptx
PPTX
IntroComputerVision23.pptx
Goal Setting UPDATED.pptx
Lec_15_OOP_ObjectsAsParametersFriendClasses.pdf
lecture-2021inheritance-160705095417.pdf
lecture-18staticdatamember-160705095116.pdf
lec09_ransac.pptx
lec07_transformations.pptx
02-07-20_Anees.pptx
Yasir Presentation.pptx
Lec5_OOP.pptx
IntroComputerVision23.pptx
Ad

Recently uploaded (20)

PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Insiders guide to clinical Medicine.pdf
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
Cell Structure & Organelles in detailed.
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Basic Mud Logging Guide for educational purpose
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
VCE English Exam - Section C Student Revision Booklet
2.FourierTransform-ShortQuestionswithAnswers.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Microbial disease of the cardiovascular and lymphatic systems
STATICS OF THE RIGID BODIES Hibbelers.pdf
Insiders guide to clinical Medicine.pdf
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Cell Structure & Organelles in detailed.
Final Presentation General Medicine 03-08-2024.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
PPH.pptx obstetrics and gynecology in nursing
Basic Mud Logging Guide for educational purpose
102 student loan defaulters named and shamed – Is someone you know on the list?
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Week 4 Term 3 Study Techniques revisited.pptx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf

Lec_1,2_OOP_(Introduction).pdf

  • 1. Women University of Azad Jammu and Kashmir Bagh Department of Computer Sciences and Information Technology, Women University of Azad Jammu and Kashmir Bagh www.wuajk.edu.pk Object Oriented Programming CS-3201 Dr. Anees Qumar Abbasi aneesabbasi.wuajk@gmail.com
  • 2. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Course Objective The course aims to focus on object-oriented concepts, analysis, and software development. This course provides in-depth coverage of object-oriented programming principles and techniques using C++, Understanding, and fundamentals (principles) of object-oriented programming: abstraction, encapsulation, polymorphism, and inheritance. Strong skills in Object Oriented programming will help students to boost their skills in software development
  • 3. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Background • It is expected that you have experience of writing and understanding programs with C. • It is also expected that students will have the knowledge of Functions, structures and Pointers.
  • 4. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Course Outline 1. Introduction to OOP: 1. What is OOP and its benefits? 2. Basic concepts: objects, classes, encapsulation, inheritance, and polymorphism. 3. Comparison between procedural programming and OOP. 2. Classes and Objects: 1. Defining classes and objects. 2. Attributes and methods. 3. Constructors and destructors. 4. Access modifiers: public, private, and protected. 3. Inheritance and Polymorphism: 1. Inheritance: extending classes, base class, and derived class. 2. Method overriding and method overloading. 3. Polymorphism: compile-time and runtime polymorphism. 4. Encapsulation and Abstraction: 1. Encapsulation: data hiding and accessors/mutators. 2. Abstraction: abstract classes and interfaces. 3. Difference between encapsulation and abstraction. 5. Association, Aggregation, and Composition: 1. Relationships between classes. 2. Association: simple and directional relationship. 3. Aggregation: "has-a" relationship. 4. Composition: strong ownership relationship. 6. Exception Handling: 1. Handling runtime errors and exceptions. 2. Try-catch blocks and exception propagation. 7. Additional Topics (time permitting): 1. Polymorphism with interfaces. 2. Abstract classes vs. interfaces. 3. Method overriding and final classes/methods.
  • 5. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Course Material Main Material Will be available through slides and Notes Reference Books: Object Oriented Programming in C++, Fourth Edition By RoberLafore, C How to Program, Sixth Edition Dietal & Dietal Object Oriented Programming in C++, IT Series www.codeproject.com www.codeguru.com www.howstuffworks.com www.whatis.com
  • 6. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Course Communication Email: aneesabbasi.wuajk@gmail.com Piazza: Piazza is a cloud-based social learning platform, which helps teachers manage classes, create student groups, post announcements, share files and lecture videos and participate in class discussions with students. Please Join: https://piazza.com/women_university_of_ajk_bagh/spring2023/cs3201
  • 7. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming How to get the goals? Read and remember Read the books, remember the language Think Think in objects, think in classes Practice Do as many coding as possible and make them running Ask Email me questions
  • 8. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Programming is the process of creating computer programs by writing instructions in a programming language to solve specific problems or automate tasks. It is a fundamental skill in the field of computer science and plays a crucial role in the development of software and technology. Programming is like writing. If you can write a demonstration, you can make a program So, programming is also easy. Programming
  • 9. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Programming But, actually, programming is not so easy, because a real good program is not easily programmed. It needs the programmers’ lots of wisdom, lots of knowledge about programming, and lots of experience. It is like writing, to be a good writer needs lots of experience and lots of knowledge about the world. Learning and practice are necessary.
  • 10. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Programming Techniques The evolution of programming techniques is: to make programming languages more expressive to develop complex systems more easily
  • 11. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Programming Techniques Unstructured Programming Procedural Programming Modular & Structural Programming Object-Oriented Programming
  • 12. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Unstructured Programming Unstructured programming is a historical programming technique characterized by a lack of high-level organization and control structures. It heavily relies on sequential execution. Usually, people start learning programming by writing small and simple programs consisting only of one main program. Here ``main program'' stands for a sequence of commands or statements which modify data that is global throughout the whole program. Main Program Data
  • 13. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Drawbacks Readability and Maintainability Code Duplication Spaghetti Code Limited Abstraction Limited Reusability Difficulty in Error Handling Lack of Scalability
  • 14. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Procedural Programming Procedural programming emphasizes the use of procedures or functions to structure code. It focuses on step-by-step procedure execution, with a main program coordinating the execution of smaller procedures. With procedural programming, you are able to combine sequences of calling statements into one single place. A procedure call is used to invoke the procedure. After the sequence is processed, the flow of control proceeds right after the position where the call was made. Main Program Procedure
  • 15. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Procedures A procedure is a named sequence of instructions or a subroutine that performs a specific task. It is a reusable block of code that can be called or invoked from different parts of a program. Procedures help in organizing code, promoting code reuse, and improving readability and maintainability. With parameters and sub-procedures (procedures of procedures), programs can now be written more structured and error-free. For example, if a procedure is correct, every time it is used it produces correct results. Consequently, in cases of errors you can narrow your search to those places which are not proven to be correct.
  • 16. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Procedural Program view Main Program Data Procedure1 Procedure2 Procedure3
  • 17. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Modular Programming Emphasizes breaking down a program into independent and self- contained modules or components. Each module represents a specific functionality or task and can be developed and maintained separately from other modules. These modules interact with each other through well-defined interfaces, promoting code reusability, maintainability, and scalability. With modular programming, procedures of a common functionality are grouped together into separate modules. A program therefore no longer consists of only one single part. It is now divided into several smaller parts which interact through procedure calls and which form the whole program.
  • 18. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Main Program(Also a module) Data Data Data1 Module2 + Data Data2 Module1 + Data Data1 Procedure1 Procedure2 The main program coordinates calls to procedures in separate modules and hands over appropriate data as parameters. Procedure3 Modular Program view
  • 19. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Modular Programming Each module can have its own data. This allows each module to manage an internal state which is modified by calls to procedures of this module. Each module has its own special functionalities that supports the implementation of the whole program.
  • 20. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Structural Programming A subset of procedural programming that enforces a logical structure on the program being written to make it more efficient and easier to understand and modify. It aims to improve the clarity, readability, and maintainability of code by enforcing a structured control flow. It emphasizes the use of control structures, such as loops and conditionals, to provide clear and organized program logic.
  • 21. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Problems with Structured Programming Many Functions access the same data, change in data may require rewriting of all functions. It makes program difficult to modify. It makes a program structure difficult to conceptualize. Arrangement of separate data and functions does a poor job of modeling things in real world.
  • 22. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Object-Oriented Programming OOP is a technique in which programs are written on the basis of objects. An object is collection of data and functions. The fundamental idea behind object oriented programming is to combine both data and functions into a single unit. Such a unit is called object. Object is derived from abstract data type. Object-oriented programming has a web of interacting objects, each house-keeping its own state. Objects of a program interact by sending messages to each other. OOP is based on real world modeling.
  • 23. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Object1 Data1+Procedures1 Data Data1 Object3 Data3 + Procedures3 Object2 Data2 + Procedures2 Object4 Data4 + Procedures4 Object-Oriented Programming – Program View
  • 24. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Object-Oriented Programming In object-oriented programming , instead of calling a procedure which we must provide with the correct handle, we would directly send a message to the object in questions. Roughly speaking, each object implements its own module. Each object is responsible to initialize and destroy itself correctly. Consequently, there is no longer the need to explicitly call a creation or termination procedure.
  • 25. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming What is an Object? Objects are tangible entities that exhibit some well-defined behavior (Almost everything is an object). Object is a fundamental building block that represents a particular instance of a class. It is a runtime entity that combines data/fields (attributes) and behavior (methods) into a single entity. An object has: Properties/State (attributes) Functions/ Well-defined behaviour (operations) Unique identity
  • 26. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Example – Ali is a Tangible Object ► State (attributes/properties/fields): Name Age Height Color ► Behaviour (operations/methods): Walks Eats Sleep ► Identity: His name
  • 27. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Example – Car is a Tangible Object ► State (attributes/properties/fields): - Color - Model ► Behaviour (operations/methods): - Accelerate - Start Car - Change Gear ► Identity: - Its registration number
  • 28. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Example – Time is an Object: Apprehended Intellectually ► State (attributes/properties/fields): ► Hours ► Seconds ► Minutes ► Behaviour (operations/methods): ► Set Hours ► Set Seconds ► Set Minutes ► Identity ► Would have a unique ID in the model
  • 29. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Class ► A Collection of objects with same properties and functions is known as class. ► A class is used to define the characteristics of the objects. Example: Person is a class that can be used to define characteristics and functions of a person. It can be used to create many objects of type Person, such as Ali, Imran etc. All objects of Person class will have same properties and functions. However, the values of each object can be different. Each object is known as instance of its class.
  • 30. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Some Facts about OOP Everything is an object. Objects perform computation by making requests of each other through the passing of messages . Every object has it's own memory, which consists of other objects. Every object is an instance of a class. A class groups similar objects. The class is the repository for behavior associated with an object
  • 31. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Features of OOP Objects OOP provides the facility of programming based in objects. Object is an entity that consists of data and functions. Classes Classes are designed to create objects. OOP provides facility to design classes. Real-world Modeling OOP is based on real-world modeling. As in the real world, things have properties and working capabilities. Similalrly, objects have data and functions. Data represents properties and functions represents working of objects. Reusability OOP provides ways to reuse data and code (inheritance). Information Hiding OOP allows the programmer to hide important data from the user (Encapsulation) Polymorphism Polymorphism is an ability of an object to behave in multiple ways.
  • 32. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Object Oriented Languages C++ JAVA C# (C Sharp) Python Many other
  • 33. Department of Computer Sciences & Information Technology Dr. Anees Qumar Abbasi- Object-Oriented Programming Implementation Language: C++ C++ is an Object Oriented language. It was developed in 1985 at Bell Laboratories. It is an improved version of C. It was originally named “C with classes”. It is very powerful language and is used to develop a variety of programs. It is very much compatible with C.