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.