Key Concept of Objected Oriented Programming,
Operating System, and System Architecture
Position applied for Assistant Professor
Dr. Bilal Yousuf
National University of Computing and Emerging Sciences
bilalmyousuf4@gmail.com
November 14, 2024
Dr. Bilal Yousuf November 14, 2024 1 / 55
Presentation Overview
1 Inheritance
2 Constructor and Destructor
3 Polymorphism
4 Virtual Functions
5 Error Handling
6 Pipelining
7 Summary
Dr. Bilal Yousuf November 14, 2024 2 / 55
Inheritance
Table of Content
1 Inheritance
2 Constructor and Destructor
3 Polymorphism
4 Virtual Functions
5 Error Handling
6 Pipelining
7 Summary
Dr. Bilal Yousuf November 14, 2024 3 / 55
Inheritance
Introduction
• Inheritance allows a class to acquire properties and behaviors
of another class, enabling reusability and hierarchical class
structure.
• Basic class hierarchy, e.g., Animal ⇒ Dog
Dr. Bilal Yousuf November 14, 2024 4 / 55
Inheritance
Definitation
Base Class
It is the class whose properties are inherited by another class, it is
also known as parent/ super class
Derived Class
It is the class that inherit properties from base class, also known as
child/sub class
Dr. Bilal Yousuf November 14, 2024 5 / 55
Inheritance
Example Code
\\base c l a s s
c l a s s Animal {
public :
void eat ( ) {
cout << ” I can eat ! ” << endl ;
}
void sleep ( ) {
cout << ” I can sleep ! ” << endl ;
}
};
\\ derived c l a s s
c l a s s Dog : p u b l i c Animal {
public :
void bark ( ) {
cout << ” I can bark ! Woof woof ! ! ” << endl ;
}
};
Dr. Bilal Yousuf November 14, 2024 6 / 55
Inheritance
continue
i n t main ( ) {
/ / Create o b j e c t of the Dog c l a s s
Dog dog1 ;
/ / C a l l i n g members of the base c l a s s
dog1 . eat ( ) ;
dog1 . sleep ( ) ;
/ / C a l l i n g member of the derived c l a s s
dog1 . bark ( ) ;
return 0 ;
}
Dr. Bilal Yousuf November 14, 2024 7 / 55
Inheritance
Visibility Modes
• It is any of the access labels: private, public, and protected
• it defines the accessability of the members of the base class
within the derive class
• if the visibility mode is not defined it will be taken as private by
default
Dr. Bilal Yousuf November 14, 2024 8 / 55
Inheritance
Modes
Dr. Bilal Yousuf November 14, 2024 9 / 55
Inheritance
Accessability
Dr. Bilal Yousuf November 14, 2024 10 / 55
Inheritance
Types of Inheritance
1 Single Inheritance
2 Multiple Inheritance
3 Hierarchy Inheritance
4 Multi-Level Inheritance
5 Hybrid Inheritance
Dr. Bilal Yousuf November 14, 2024 11 / 55
Inheritance
Single Inheritance
• Implement an “is-a” relationship
• The derived class only has one base class
Dr. Bilal Yousuf November 14, 2024 12 / 55
Inheritance
Syntax
c l a s s DerivedClassName : [ V i s i b i l i t y Mode] BaseClassName
{
\\ DataMembers and MemberFunctions ;
}
Example:
c l a s s Automobile : p u b l i c V e h i c l e
{
\\ DataMembers and MemberFunctions ;
}
Dr. Bilal Yousuf November 14, 2024 13 / 55
Inheritance
Multiple Inheritance
• Derivation of a class from Several (Two or More) base class is
called multiple inheritance
Dr. Bilal Yousuf November 14, 2024 14 / 55
Inheritance
Syntax
c l a s s DerivedClassName : [ V i s i b i l i t y Mode] BaseClassName1 ,
[ V i s i b i l i t y Mode] BaseClassName2 ,
{
\\ DataMembers and MemberFunctions ;
}
Example:
c l a s s c h i l d : p u b l i c Father , p u b l i c Mother
{
\\ DataMembers and MemberFunctions ;
}
Dr. Bilal Yousuf November 14, 2024 15 / 55
Inheritance
Hierarchy Inheritance
• Derivation of Several classes from Single base class is called
Hierarchy Inheritance
Dr. Bilal Yousuf November 14, 2024 16 / 55
Inheritance
Syntax
c l a s s DerivedClassName1 : [ V i s i b i l i t y Mode] BaseClassName
{
\\ DataMembers and MemberFunctions ;
}
c l a s s DerivedClassName2 : [ V i s i b i l i t y Mode] BaseClassName
{
\\ DataMembers and MemberFunctions ;
}
Example:
c l a s s c h i l d 1 : p u b l i c Father
{
\\ DataMembers and MemberFunctions ;
}
c l a s s c h i l d 2 : p u b l i c Father
{
\\ DataMembers and MemberFunctions ;
}
Dr. Bilal Yousuf November 14, 2024 17 / 55
Inheritance
Multi-Level Inheritance
• When a sub-class is derived from a base class which itself
derived from another class, is called multi-level inheritance
Dr. Bilal Yousuf November 14, 2024 18 / 55
Inheritance
Syntax
c l a s s DerivedClassName1 : [ V i s i b i l i t y Mode] BaseClassName
{
\\ DataMembers and MemberFunctions ;
}
c l a s s DerivedClassName2 : [ V i s i b i l i t y Mode] DerviedClassName1
{
\\ DataMembers and MemberFunctions ;
}
Example:
class Y : publicX
{
\\ DataMembers and MemberFunctions ;
}
class Z : public Y
{
\\ DataMembers and MemberFunctions ;
}
Dr. Bilal Yousuf November 14, 2024 19 / 55
Inheritance
Hybrid Inheritance
• Derivation of a class involving more than one from of
inheritance is known as hybrid inheritance
Dr. Bilal Yousuf November 14, 2024 20 / 55
Constructor and Destructor
Table of Content
1 Inheritance
2 Constructor and Destructor
3 Polymorphism
4 Virtual Functions
5 Error Handling
6 Pipelining
7 Summary
Dr. Bilal Yousuf November 14, 2024 21 / 55
Constructor and Destructor
Constructor
• A constructor is a special member function of a class and
shares the same name as of class, which means the
constructor and class have the same name
• Constructor is called by the compiler whenever the object of
the class is created
• it allocates the memory to the object and initializes class data
members by default values or values passed by the user while
creating an object
c l a s s class name {
private :
/ / p r i v a t e members
public :
/ / declaring constructor
class name ( { parameters } )
{
/ / c o n s t r u c t o r body
}
};
Dr. Bilal Yousuf November 14, 2024 22 / 55
Constructor and Destructor
Types of Constructors
1 Default Constructor
2 Parameterized Constructor
3 Copy Constructor
4 Dynamic Constructor
Dr. Bilal Yousuf November 14, 2024 23 / 55
Constructor and Destructor
Default Constructor
c l a s s Person{
private :
s t r i n g name ;
public :
Person ( )
{
cout<<”De fau lt c o n s t r u c t o r i s c a l l e d”<<endl ;
name = ” student ” ;
}
void d i s p l a y ( )
{
cout<<”Name of current o b j e c t : ”<<name<<endl ;
}
};
i n t main ( )
{
Person obj ;
obj . d i s p l a y ( ) ;
return 0 ;
}
Dr. Bilal Yousuf November 14, 2024 24 / 55
Constructor and Destructor
Parameterized Constructor
c l a s s Person{
private :
s t r i n g name ;
public :
Person ( s t r i n g person name )
{
cout<<”Constructor to s e t name i s c a l l e d”<<endl ;
name = person name ;
}
void d i s p l a y ( )
{
cout<<”Name of current o b j e c t : ”<<name<<endl ;
}
};
i n t main ( )
{
Person obj1 ( ” F i r s t person ” ) ;
obj1 . d i s p l a y ( ) ;
return 0 ;
}
Dr. Bilal Yousuf November 14, 2024 25 / 55
Constructor and Destructor
Copy Constructor
c l a s s Person{
private :
s t r i n g name ;
public :
Person ( s t r i n g person name )
{cout<<”Constructor f o r both name and age i s c a l l e d”<<endl ;
name = person name ;
}
Person ( const Person& obj )
{ cout<<”Copy c o n s t r u c t o r i s c a l l e d”<<endl ; name = obj . name ;
}
void d i s p l a y ( )
{ cout<<”Name of current o b j e c t : ”<<name<<endl ;
}
};
i n t main ( )
{
Person obj1 ( ” F i r s t person ” ) ; obj1 . d i s p l a y ( ) ;
Person obj2 ( obj1 ) ;
return 0 ;
}
Dr. Bilal Yousuf November 14, 2024 26 / 55
Constructor and Destructor
Dynamic Constructor
c l a s s Person{
private :
i n t * age ;
public :
Person ( i n t * person age )
{
cout<<”Constructor f o r age i s c a l l e d”<<endl ;
age = new i n t ;
age = person age ; }
void d i s p l a y ( )
{
cout<<”Age of current o b j e c t : ”<<*age<<endl ;
cout<<endl ; }
};
i n t main ( )
{
i n t age = 25;
Person obj1 (&age ) ;
obj1 . d i s p l a y ( ) ;
return 0 ; }
Dr. Bilal Yousuf November 14, 2024 27 / 55
Constructor and Destructor
Destructor
• A destructor is called by the compiler when the object is
destroyed and its main function is to deallocate the memory of
the object
• The object may be destroyed when the program ends, or local
objects of the function get out of scope when the function
ends or in any other case
• Destructor has the same as of the class with prefix tilde(˜)
operator and it cannot be overloaded as the constructor
Dr. Bilal Yousuf November 14, 2024 28 / 55
Constructor and Destructor
Syntax
c l a s s class name {
private :
int a ;
public :
class name ( i n t aa )
{
cout<<”Constructor i s c a l l e d”<<endl ;
a = aa ;
cout<<”Value of a : ”<<a<<endl ;
}
˜class name ( )
{
cout<<”Destructor i s c a l l e d”<<endl ;
cout<<”Value of a : ”<<a<<endl ;
}
};
i n t main ( )
{
class name obj ( 5 ) ;
return 0 ;
}
Dr. Bilal Yousuf November 14, 2024 29 / 55
Polymorphism
Table of Content
1 Inheritance
2 Constructor and Destructor
3 Polymorphism
4 Virtual Functions
5 Error Handling
6 Pipelining
7 Summary
Dr. Bilal Yousuf November 14, 2024 30 / 55
Polymorphism
Polymorphism
• Ploymorphism is derived from 2 Greek words: poly and
morphs, it means many forms
Definition
The process of representing one form in multiple form or The
ability to take more than one form
Dr. Bilal Yousuf November 14, 2024 31 / 55
Polymorphism
Advantages and Disadvantages
Advantages
• It helps to reuse the code in many ways whenever is needed
• Single variable name can be used to store variables of multiple
data types (Float double long etc)
Disadvantages
• Polymorphism reduces the readability of the code
• Developers find it difficult to implement polymorphism in
codes
Dr. Bilal Yousuf November 14, 2024 32 / 55
Polymorphism
Types of Polymorphism
1 Method Overloading (Compile time)
• It is also known as Static binding, Early binding
2 Method Overriding (Run time)
• It is also known as Dynamic binding, Late binding
• Dynamic binding is the process to call a specific sequence of
code at run time
Dr. Bilal Yousuf November 14, 2024 33 / 55
Polymorphism
Method Overloading
• A class has multiple method with the same name but different
parameters
p u b l i c c l a s s Overloading {
s t a t i c c l a s s Methoverloading{
Void t e s t ( ) {
cout<<”No parameters”<<endl ; }
Void t e s t ( i n t a ) {
cout<<”a : ” +a <<endl ; }
}
p u b l i c s t a t i c void main ( s t r i n g [ ] args ) {
Methoverloading ob=new
Methoverloading ( ) ;
ob . t e s t ( ) ; ob . t e s t ( 1 0 ) ; } }
Dr. Bilal Yousuf November 14, 2024 34 / 55
Polymorphism
Method Overriding
• Base and derived class having methods with same name and
same parameters, but having different implementations
p u b l i c c l a s s Overriding {
s t a t i c c l a s s Animal{
p u b l i c Void move ( ) {
cout<<”Animals can move”<<endl ; } }
S t a t i c c l a s s Dog extends animal{
@Override
p u b l i c Void move ( ) {
cout<<”Dogs can walk and run”<<endl ; } }
p u b l i c s t a t i c void main ( s t r i n g [ ] args ) {
Dog obj=new Dog ( ) ;
obj . move ( ) ;
}
}
Dr. Bilal Yousuf November 14, 2024 35 / 55
Virtual Functions
Table of Content
1 Inheritance
2 Constructor and Destructor
3 Polymorphism
4 Virtual Functions
5 Error Handling
6 Pipelining
7 Summary
Dr. Bilal Yousuf November 14, 2024 36 / 55
Virtual Functions
Virtual Function
• Virtual means existing in appearance but not in reality
• When virtual functions are used, a program that appears to be
calling a function of one class may in reality be calling a
function of different class
• Normal member function accessed with pointers
Dr. Bilal Yousuf November 14, 2024 37 / 55
Virtual Functions
Example
c l a s s base {
public :
v i r t u a l void p r i n t ( ) { cout << ” p r i n t base c l a s s \n ” ; }
void show ( ) { cout << ” show base c l a s s \n ” ; }
};
c l a s s derived : p u b l i c base {
public :
void p r i n t ( ) { cout << ” p r i n t derived c l a s s \n ” ; }
void show ( ) { cout << ” show derived c l a s s \n ” ; }
};
i n t main ( )
{
base * bptr ; derived d ; bptr = &d ;
/ / V i r t u a l function , binded at runtime
bptr−>p r i n t ( ) ;
/ / Non− v i r t u a l function , binded at compile time
bptr−>show ( ) ;
return 0 ;
}
Dr. Bilal Yousuf November 14, 2024 38 / 55
Error Handling
Table of Content
1 Inheritance
2 Constructor and Destructor
3 Polymorphism
4 Virtual Functions
5 Error Handling
6 Pipelining
7 Summary
Dr. Bilal Yousuf November 14, 2024 39 / 55
Error Handling
Introduction
• An operating system is defined as an interface between the
computer system and its users
• Once the operating system is loaded into the computer system
through the boot program it is responsible for managing all
the applications on the device
• There may be some errors that can cause the system to have
some severe fault which can lead to false results to handle this
error handling should be properly applied
Dr. Bilal Yousuf November 14, 2024 40 / 55
Error Handling
Error and its Types
Error
• An error is an abnormal condition or scenario that basically
occurs in the operating system that basically restricts the
system from performing the desired or expected action
• The sources of these errors can be runtime errors, logical
errors, system crashes, and many more
There are two types of errors
1 Transient Failure
2 Permanent Failure
Dr. Bilal Yousuf November 14, 2024 41 / 55
Error Handling
Definitions
Transient Failure
• Transient failures are basically defined as temporary or
short-term errors that occur in the system, or in a certain
process
• Example: Deadlock Condition, where processes cause
temporary conflicts in accessing shared resources
Permanent Failure
• Permanent failure is the most severe problem, or severe error
in the operating system, which cannot be recovered or
resolved through some error handling activities
• Example: Defective CPU that constantly generates incorrect
results or false outputs
Dr. Bilal Yousuf November 14, 2024 42 / 55
Error Handling
Error Handling
• Error handling in an operating system basically refers to the
systematic process or systematic approach for Detecting,
Managing, and properly responding to the errors that actually
occurred by some failures,
• Error handling in an operating system consists of some
mechanisms or some solutions to handle these types of
failures or exceptions or some unexpected scenarios
• The main aim of this error handling in the operating system is
to basically handle the errors which have occurred in runtime
or in compile time in an efficient and stable manner
• Error handling consists of some of the strategies, like
exception handling, error codes, and messages, retry
mechanisms, Logging and debugging, etc
Dr. Bilal Yousuf November 14, 2024 43 / 55
Error Handling
Error Handling Benefit
1 Robustness and Reliability :It basically allows us to properly
and efficiently handle failures And exceptional conditions
without crashing or making the processes or software halt
2 Improves User Experience: When a Failure or area occurs in
our operating system, or in some process, there should be
some clear and relevant error messages, so that the user can
troubleshoot the error
3 Maintains Security: Efficient error handling process also helps
the system security by providing relevant and useful error
messages without compromising any sensitive information
4 Problem Troubleshooting and Debugging: When errors are
properly logged and reported, a system administrator who
takes care of the entire system, developer can analyse these
error details to identify the cause of the errors or failures
Dr. Bilal Yousuf November 14, 2024 44 / 55
Error Handling
Example: Transient Failure
we will consider a scenario where a system user wants to read the
file from the local disc drive using the operating system’s file
input-output of functions
• Transient Failure: Once the user initiates this process for
reading the content from the file, a transient failure occurs,
where the file read operation is stopped due to momentary
power fluctuation
• Operating System Response (Error Handling): The operating
system reattempts or performs retries to build the
communication with the disc drive and continues the file read
operation from where it was stopped, or from where it was
getting disconnected.
Dr. Bilal Yousuf November 14, 2024 45 / 55
Error Handling
Example: Permanent Failure
we will consider a scenario where a system user wants to read the
file from the local disc drive using the operating system’s file
input-output of functions
• Permanent Failure: So in permanent failure, the external USB
drive encounters a severe physical failure in the read and write
head, which makes it impossible or problematic for the
operating system to access any data on that particular drive
• Operating System Response (Error Handling): in this case, the
operating system directly cannot recover from the hardware
defect. It actually returns an error code that specifies to the
user the actual problem which has been caused. The user is
also advised to check its drives connection or take some
professional assistance help so that they can perform the data
recovery action
Dr. Bilal Yousuf November 14, 2024 46 / 55
Pipelining
Table of Content
1 Inheritance
2 Constructor and Destructor
3 Polymorphism
4 Virtual Functions
5 Error Handling
6 Pipelining
7 Summary
Dr. Bilal Yousuf November 14, 2024 47 / 55
Pipelining
Definition
• Pipelining is a technique used in modern processors to
improve performance by executing multiple instructions
simultaneously
• It breaks down the execution of instructions into several
stages, where each stage completes a part of the instruction
• These stages can overlap, allowing the processor to work on
different instructions at various stages of completion,
Dr. Bilal Yousuf November 14, 2024 48 / 55
Pipelining
Example
Laundry Example Ann, Brian, Cathy and Dave, each have one load
of clothes to wash, dry, and fold Washer takes 30 minutes Dryer
takes 40 minutes, and Folder takes 20 minutes
Dr. Bilal Yousuf November 14, 2024 49 / 55
Pipelining
Standard Vs Pipelining
Figure: Standard method Figure: Pipelining method
Dr. Bilal Yousuf November 14, 2024 50 / 55
Pipelining
Continue...
• Pipelining doesn’t help latency of single task, it helps
throughput of entire workload
• Pipeline rate limited by slowest pipeline stage
• Multiple tasks operating simultaneously
• Potential speedup = Number pipe stages
• Unbalanced lengths of pipe stages reduces speedup
• Time to “fill” pipeline and time to “drain” it reduces speedup
Dr. Bilal Yousuf November 14, 2024 51 / 55
Pipelining
Advantages vs Disadvantages
Advantages
• Pipelining enables different CPU sections to operate
simultaneously by overlapping instruction stages
• As one instruction executes, others can be in fetch, decode, or
other stages, improving efficiency
• Pipelining is adaptable across various processor types, from
simple CPUs to advanced multi-core processors
Disadvantages
• Pipelining can lead to data, control, and structural hazards due
to instruction dependencies, branching, and limited hardware
resources
• It increases design complexity compared to non-pipelined
structures
Dr. Bilal Yousuf November 14, 2024 52 / 55
Summary
Table of Content
1 Inheritance
2 Constructor and Destructor
3 Polymorphism
4 Virtual Functions
5 Error Handling
6 Pipelining
7 Summary
Dr. Bilal Yousuf November 14, 2024 53 / 55
Summary
Summary
• Inheritance in OOP: Explains how classes acquire properties
from other classes, covering types like single, multiple, and
hybrid inheritance
• Polymorphism: Describes method overloading and overriding,
enabling flexibility by allowing multiple forms of a function
within a class structure
• Error handling ensures system stability by detecting and
managing temporary and permanent failures, using retries,
logging, and error codes to maintain robustness, security, and
user clarity
• Pipelining in System Architecture: Technique to enhance CPU
performance by overlapping instruction stages, increasing
throughput but introducing design complexity
Dr. Bilal Yousuf November 14, 2024 54 / 55
The End
Questions? Comments?