SlideShare a Scribd company logo
1 of 73
Object Oriented Programming Department  of Computer Science, University of Peshawar Lecture 03 Introduction Introduction Lec - 03
Outline ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar
Abstraction ,[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Abstraction ,[object Object],[object Object],[object Object],Lecture 02 Introduction Department  of Computer Science, University of Peshawar Lecture 03 Introduction
Example - Abstraction ,[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example - Abstraction ,[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example - Abstraction ,[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example - Abstraction ,[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Abstraction - Advantage ,[object Object],[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar
Class ,[object Object]
Example - Class ,[object Object],[object Object],[object Object],[object Object],[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar
Example - Class ,[object Object],[object Object],[object Object],[object Object],[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar
Lecture 03 Introduction Department  of Computer Science, University of Peshawar
Declaration of an Object class Rectangle { private:   int width;   int length; public:   void set(int w, int l);   int area(); } main() {   Rectangle r1; r1.set(5, 8);  } r1 is statically allocated width length r1 width = 5 length = 8 Lecture 03 Introduction
Difference Between Object And Class ,[object Object],[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar
Difference Between Object And Class (continue) ,[object Object],[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar
Inheritance ,[object Object],[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar
Inheritance in classes ,[object Object],[object Object],[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar
Example - Inheritance Lecture 03 Introduction Department  of Computer Science, University of Peshawar Person Teacher Student Doctor
Inheritance Concept Rectangle Triangle Polygon class Polygon { private:   int width, length; public:   void set(int w, int l); } class Rectangle{ private:   int width, length; public:   void set(int w, int l);   int area(); } class Triangle{ private:   int width, length; public:   void set(int w, int l);   int area(); } Lecture 03 Introduction
Inheritance Concept Rectangle Triangle Polygon class Polygon { protected:   int width, length; public:   void set(int w, int l); } class Rectangle : public Polygon { public:   int area(); } class Rectangle{ protected:   int width, length; public:   void set(int w, int l);   int area(); } Lecture 03 Introduction
Inheritance Concept Rectangle Triangle Polygon class Polygon { protected:   int width, length; public:   void set(int w, int l); } class Triangle : public Polygon { public: int area(); } class Triangle{ protected:   int width, length; public:   void set(int w, int l);   int area(); } Lecture 03 Introduction
Inheritance Concept Point Circle 3D-Point class Point { protected:   int x, y; public:   void set(int a, int b); } class Circle : public Point { private:  double r; } class 3D-Point: public Point { private:  int z; } x y x y r x y z Lecture 03 Introduction
[object Object],[object Object],Inheritance Concept RealNumber ComplexNumber ImaginaryNumber Rectangle Triangle Polygon Point Circle real imag real imag 3D-Point Lecture 03 Introduction
Inheritance – “IS A” or “IS A KIND OF” Relationship ,[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar
Example – “IS A” Relatioship Lecture 03 Introduction Department  of Computer Science, University of Peshawar Person Name Age Gender Eat walk Student Program Study_year Study Heldexam Teacher designation salary Teach Take_exam Doctor designation salary Check up prescribe
Example – “IS A” Relatioship Lecture 03 Introduction Department  of Computer Science, University of Peshawar shape color coordinates Draw rotate Set color Circle radius draw Compute area Line length Draw Triangle angle Draw Compute area
Inheritance – Advantages ,[object Object],[object Object],[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar
Reuse with  Inheritance ,[object Object],[object Object],[object Object],[object Object],[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar
Example Reuse Lecture 03 Introduction Department  of Computer Science, University of Peshawar Shape color coordinates Draw rotate Set color Circle radius draw Compute area Line length Draw Triangle angle Draw Compute area
Example – “IS A” Relatioship Lecture 03 Introduction Department  of Computer Science, University of Peshawar Person Name Age Gender Eat walk Student Program Study_year Study Heldexam Teacher designation salary Teach Take_exam Doctor designation salary Check up prescribe
Example – “IS A” Relatioship Lecture 03 Introduction Department  of Computer Science, University of Peshawar Person Name Age Gender Eat walk Student Program Study_year Study Heldexam Teacher designation salary Teach Take_exam Doctor designation salary Check up prescribe
Example Reuse Lecture 03 Introduction Department  of Computer Science, University of Peshawar Person Name Age Gender Eat walk Student Program Study_year Study Heldexam Teacher designation salary Teach Take_exam Doctor designation salary Check up prescribe
Concepts Related with Inheritance ,[object Object],[object Object],[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar
Generalization ,[object Object],[object Object],[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar
Example Generalization Lecture 03 Introduction Department  of Computer Science, University of Peshawar Student Name Age gender Program Study_year Eat walk Study Heldexam Teacher Name age gender designation salary Eat walk Teach Take_exam Doctor Name Age gender designation salary Eat walk Check up prescribe
Example - Generalization Lecture 03 Introduction Department  of Computer Science, University of Peshawar Person Name Age Gender Eat walk Student Program Study_year Study Heldexam Teacher designation salary Teach Take_exam Doctor designation salary Check up prescribe
Sub-typing & Specialization ,[object Object],[object Object],[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar
Example – Sub-typing (Extension) Lecture 03 Introduction Department  of Computer Science, University of Peshawar Person Name Age Gender Eat walk Student Program Study_year Study Heldexam
Specialization (Restriction) ,[object Object],[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar
Example – Specialization (Restriction) Lecture 03 Introduction Department  of Computer Science, University of Peshawar Person Age: [0…..100] Set Age(a) Adult Age: [18….100] Set Age(a) Age = a If age<18 Error Else Age = a
Example – Specialization (Restriction) Lecture 03 Introduction Department  of Computer Science, University of Peshawar integerSet ---------- Add ( element) Natural Set ------- Add ( element) Add element  To the set If element<1 Error Else Add element to the  set
Method Overriding ,[object Object],[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar
… Method Overriding.. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar
Example – Specific Behavior Lecture 03 Introduction Department  of Computer Science, University of Peshawar shape color coordinates Draw rotate Set color Circle radius draw Compute area Line length Draw Triangle angle Draw Compute area
Example – Improve Performance Lecture 03 Introduction Department  of Computer Science, University of Peshawar Shape color coord draw Rotate Set color Circle redius Draw Rotate ,[object Object],[object Object],[object Object],[object Object],[object Object]
Abstract Classes ,[object Object],[object Object],[object Object],[object Object],Lecture 03 Introduction Department  of Computer Science, University of Peshawar
Example – Abstract Classes Lecture 03 Introduction Department  of Computer Science, University of Peshawar Person Name Age Gender Eat walk Student Teacher Doctor ,[object Object]
Concrete Classes ,[object Object],[object Object],[object Object],Lecture 03 Introduction
Example – Concrete Classes Lecture 03 Introduction Department  of Computer Science, University of Peshawar Person Name Age Gender Eat walk Student Teacher Doctor ,[object Object],Program Study Year Study Held Exam
Types of Inheritance ,[object Object],[object Object],[object Object],[object Object]
Types of Inheritance
Multiple Inheritance ,[object Object],[object Object]
Example – Multiple Inheritance
Example – Multiple Inheritance Land Vehicle Vehicle Water Vehicle Car Amphibious Vehicle Boot
Problems with multiple  Inheritance ,[object Object],[object Object],[object Object]
… Problems with multiple  Inheritance… ,[object Object],[object Object]
..Problems with multiple  Inheritance..
Solution – Override the common Feature ,[object Object],Land Vehicle Change Gear Water Vehicle Car Amphibious Vehicle Boot Vehicle
Composition – “has-a” relationship ,[object Object],[object Object],[object Object]
Example – Composition of Ali ,[object Object],[object Object],[object Object],[object Object],Head Ali Arms legs Head
Example – Composition of chair ,[object Object],[object Object],Lecture 03 Introduction Back Chair Arm seat Leg
Composition is Stronger ,[object Object],[object Object],[object Object],[object Object]
Example - Composition is Stronger ,[object Object],[object Object]
Example - Composition is Stronger ,[object Object],[object Object]
Aggregation ,[object Object],[object Object],[object Object]
Example – Aggregation ,[object Object],[object Object],[object Object],[object Object],Bed Room Chair Table Cupboard
Aggregation ,[object Object],[object Object]
Aggregation ,[object Object],[object Object],[object Object]
Aggregation is weaker ,[object Object],[object Object],[object Object],[object Object]
Example - Aggregation is weaker ,[object Object],[object Object]
Quizz (time-10 mins) ,[object Object],[object Object]
[object Object],Thanks Lecture 03 Introduction

More Related Content

Viewers also liked

The entity relationship model
The entity relationship modelThe entity relationship model
The entity relationship model
Jane Garay
 
OOP programming
OOP programmingOOP programming
OOP programming
anhdbh
 
Engineering kpi examples
Engineering kpi examplesEngineering kpi examples
Engineering kpi examples
gallaravumartin
 
Seminar on 3 d internet
Seminar on 3 d internetSeminar on 3 d internet
Seminar on 3 d internet
Pabitra Padhy
 
Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship Model
Slideshare
 
Lecture 10 distributed database management system
Lecture 10   distributed database management systemLecture 10   distributed database management system
Lecture 10 distributed database management system
emailharmeet
 

Viewers also liked (20)

The entity relationship model
The entity relationship modelThe entity relationship model
The entity relationship model
 
Software Basics
Software BasicsSoftware Basics
Software Basics
 
Unified Modeling Language (UML), Object-Oriented Programming Concepts & Desig...
Unified Modeling Language (UML), Object-Oriented Programming Concepts & Desig...Unified Modeling Language (UML), Object-Oriented Programming Concepts & Desig...
Unified Modeling Language (UML), Object-Oriented Programming Concepts & Desig...
 
OOP programming
OOP programmingOOP programming
OOP programming
 
NoSQL Databases - Lecture 12 - Introduction to Databases (1007156ANR)
NoSQL Databases - Lecture 12 - Introduction to Databases (1007156ANR)NoSQL Databases - Lecture 12 - Introduction to Databases (1007156ANR)
NoSQL Databases - Lecture 12 - Introduction to Databases (1007156ANR)
 
Unit 02 dbms
Unit 02 dbmsUnit 02 dbms
Unit 02 dbms
 
Database design
Database designDatabase design
Database design
 
Object Oriented Programming - Introduction
Object Oriented Programming - IntroductionObject Oriented Programming - Introduction
Object Oriented Programming - Introduction
 
Engineering kpi examples
Engineering kpi examplesEngineering kpi examples
Engineering kpi examples
 
The opportunity in computer science
The opportunity in computer scienceThe opportunity in computer science
The opportunity in computer science
 
10 Myths for Computer Science
10 Myths for Computer Science10 Myths for Computer Science
10 Myths for Computer Science
 
Seminar on 3 d internet
Seminar on 3 d internetSeminar on 3 d internet
Seminar on 3 d internet
 
Extended ER Model and other Modelling Languages - Lecture 2 - Introduction to...
Extended ER Model and other Modelling Languages - Lecture 2 - Introduction to...Extended ER Model and other Modelling Languages - Lecture 2 - Introduction to...
Extended ER Model and other Modelling Languages - Lecture 2 - Introduction to...
 
What does OOP stand for?
What does OOP stand for?What does OOP stand for?
What does OOP stand for?
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship Model
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
 
Bhim app
Bhim appBhim app
Bhim app
 
What is OOP?
What is OOP?What is OOP?
What is OOP?
 
Lecture 10 distributed database management system
Lecture 10   distributed database management systemLecture 10   distributed database management system
Lecture 10 distributed database management system
 

Similar to Oop Introduction

Student self-assessment of the development of advanced scientific thinking sk...
Student self-assessment of the development of advanced scientific thinking sk...Student self-assessment of the development of advanced scientific thinking sk...
Student self-assessment of the development of advanced scientific thinking sk...
Kirsten Zimbardi
 
Ibdp physics exetended essay and army ppt.pptx
Ibdp physics exetended essay and army ppt.pptxIbdp physics exetended essay and army ppt.pptx
Ibdp physics exetended essay and army ppt.pptx
Aarti Akela
 
Java căn bản - Chapter13
Java căn bản - Chapter13Java căn bản - Chapter13
Java căn bản - Chapter13
Vince Vo
 
Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1
PRN USM
 
Technology Integration
Technology IntegrationTechnology Integration
Technology Integration
jjaffe
 
Dynamic Question Answer Generator An Enhanced Approach to Question Generation
Dynamic Question Answer Generator An Enhanced Approach to Question GenerationDynamic Question Answer Generator An Enhanced Approach to Question Generation
Dynamic Question Answer Generator An Enhanced Approach to Question Generation
ijtsrd
 

Similar to Oop Introduction (20)

Concept of Classes in c++.ist mse16.pptx
Concept of Classes in c++.ist mse16.pptxConcept of Classes in c++.ist mse16.pptx
Concept of Classes in c++.ist mse16.pptx
 
OOAD - UML - Class and Object Diagrams - Lab
OOAD - UML - Class and Object Diagrams - LabOOAD - UML - Class and Object Diagrams - Lab
OOAD - UML - Class and Object Diagrams - Lab
 
Eclass Model
Eclass ModelEclass Model
Eclass Model
 
Helping Students to Learn Matehmatics Beyond LMS
Helping Students to Learn Matehmatics Beyond LMSHelping Students to Learn Matehmatics Beyond LMS
Helping Students to Learn Matehmatics Beyond LMS
 
Ail apresentation(kumazawa)
Ail apresentation(kumazawa)Ail apresentation(kumazawa)
Ail apresentation(kumazawa)
 
Student self-assessment of the development of advanced scientific thinking sk...
Student self-assessment of the development of advanced scientific thinking sk...Student self-assessment of the development of advanced scientific thinking sk...
Student self-assessment of the development of advanced scientific thinking sk...
 
Ibdp physics exetended essay and army ppt.pptx
Ibdp physics exetended essay and army ppt.pptxIbdp physics exetended essay and army ppt.pptx
Ibdp physics exetended essay and army ppt.pptx
 
Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674
 
Core java complete notes - PAID call at +91-814-614-5674
Core java complete notes - PAID call at +91-814-614-5674Core java complete notes - PAID call at +91-814-614-5674
Core java complete notes - PAID call at +91-814-614-5674
 
CURRICULUM VITAE
CURRICULUM VITAECURRICULUM VITAE
CURRICULUM VITAE
 
eLearning in practice in Higher Education by Prof. Edward Reeve
eLearning in practice in Higher Education by Prof. Edward ReeveeLearning in practice in Higher Education by Prof. Edward Reeve
eLearning in practice in Higher Education by Prof. Edward Reeve
 
Java căn bản - Chapter13
Java căn bản - Chapter13Java căn bản - Chapter13
Java căn bản - Chapter13
 
Chapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and PolymorphismChapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and Polymorphism
 
Wi13 Workshop - Teaching as Research
Wi13 Workshop - Teaching as ResearchWi13 Workshop - Teaching as Research
Wi13 Workshop - Teaching as Research
 
Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1
 
Technology Integration
Technology IntegrationTechnology Integration
Technology Integration
 
ICTERI-2021-seidametova.pdf
ICTERI-2021-seidametova.pdfICTERI-2021-seidametova.pdf
ICTERI-2021-seidametova.pdf
 
Light structural systems_for_covering_large_spans
Light structural systems_for_covering_large_spansLight structural systems_for_covering_large_spans
Light structural systems_for_covering_large_spans
 
Dynamic Question Answer Generator An Enhanced Approach to Question Generation
Dynamic Question Answer Generator An Enhanced Approach to Question GenerationDynamic Question Answer Generator An Enhanced Approach to Question Generation
Dynamic Question Answer Generator An Enhanced Approach to Question Generation
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 

Recently uploaded

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Recently uploaded (20)

Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 

Oop Introduction

  • 1. Object Oriented Programming Department of Computer Science, University of Peshawar Lecture 03 Introduction Introduction Lec - 03
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13. Lecture 03 Introduction Department of Computer Science, University of Peshawar
  • 14. Declaration of an Object class Rectangle { private: int width; int length; public: void set(int w, int l); int area(); } main() { Rectangle r1; r1.set(5, 8); } r1 is statically allocated width length r1 width = 5 length = 8 Lecture 03 Introduction
  • 15.
  • 16.
  • 17.
  • 18.
  • 19. Example - Inheritance Lecture 03 Introduction Department of Computer Science, University of Peshawar Person Teacher Student Doctor
  • 20. Inheritance Concept Rectangle Triangle Polygon class Polygon { private: int width, length; public: void set(int w, int l); } class Rectangle{ private: int width, length; public: void set(int w, int l); int area(); } class Triangle{ private: int width, length; public: void set(int w, int l); int area(); } Lecture 03 Introduction
  • 21. Inheritance Concept Rectangle Triangle Polygon class Polygon { protected: int width, length; public: void set(int w, int l); } class Rectangle : public Polygon { public: int area(); } class Rectangle{ protected: int width, length; public: void set(int w, int l); int area(); } Lecture 03 Introduction
  • 22. Inheritance Concept Rectangle Triangle Polygon class Polygon { protected: int width, length; public: void set(int w, int l); } class Triangle : public Polygon { public: int area(); } class Triangle{ protected: int width, length; public: void set(int w, int l); int area(); } Lecture 03 Introduction
  • 23. Inheritance Concept Point Circle 3D-Point class Point { protected: int x, y; public: void set(int a, int b); } class Circle : public Point { private: double r; } class 3D-Point: public Point { private: int z; } x y x y r x y z Lecture 03 Introduction
  • 24.
  • 25.
  • 26. Example – “IS A” Relatioship Lecture 03 Introduction Department of Computer Science, University of Peshawar Person Name Age Gender Eat walk Student Program Study_year Study Heldexam Teacher designation salary Teach Take_exam Doctor designation salary Check up prescribe
  • 27. Example – “IS A” Relatioship Lecture 03 Introduction Department of Computer Science, University of Peshawar shape color coordinates Draw rotate Set color Circle radius draw Compute area Line length Draw Triangle angle Draw Compute area
  • 28.
  • 29.
  • 30. Example Reuse Lecture 03 Introduction Department of Computer Science, University of Peshawar Shape color coordinates Draw rotate Set color Circle radius draw Compute area Line length Draw Triangle angle Draw Compute area
  • 31. Example – “IS A” Relatioship Lecture 03 Introduction Department of Computer Science, University of Peshawar Person Name Age Gender Eat walk Student Program Study_year Study Heldexam Teacher designation salary Teach Take_exam Doctor designation salary Check up prescribe
  • 32. Example – “IS A” Relatioship Lecture 03 Introduction Department of Computer Science, University of Peshawar Person Name Age Gender Eat walk Student Program Study_year Study Heldexam Teacher designation salary Teach Take_exam Doctor designation salary Check up prescribe
  • 33. Example Reuse Lecture 03 Introduction Department of Computer Science, University of Peshawar Person Name Age Gender Eat walk Student Program Study_year Study Heldexam Teacher designation salary Teach Take_exam Doctor designation salary Check up prescribe
  • 34.
  • 35.
  • 36. Example Generalization Lecture 03 Introduction Department of Computer Science, University of Peshawar Student Name Age gender Program Study_year Eat walk Study Heldexam Teacher Name age gender designation salary Eat walk Teach Take_exam Doctor Name Age gender designation salary Eat walk Check up prescribe
  • 37. Example - Generalization Lecture 03 Introduction Department of Computer Science, University of Peshawar Person Name Age Gender Eat walk Student Program Study_year Study Heldexam Teacher designation salary Teach Take_exam Doctor designation salary Check up prescribe
  • 38.
  • 39. Example – Sub-typing (Extension) Lecture 03 Introduction Department of Computer Science, University of Peshawar Person Name Age Gender Eat walk Student Program Study_year Study Heldexam
  • 40.
  • 41. Example – Specialization (Restriction) Lecture 03 Introduction Department of Computer Science, University of Peshawar Person Age: [0…..100] Set Age(a) Adult Age: [18….100] Set Age(a) Age = a If age<18 Error Else Age = a
  • 42. Example – Specialization (Restriction) Lecture 03 Introduction Department of Computer Science, University of Peshawar integerSet ---------- Add ( element) Natural Set ------- Add ( element) Add element To the set If element<1 Error Else Add element to the set
  • 43.
  • 44.
  • 45. Example – Specific Behavior Lecture 03 Introduction Department of Computer Science, University of Peshawar shape color coordinates Draw rotate Set color Circle radius draw Compute area Line length Draw Triangle angle Draw Compute area
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 53.
  • 54. Example – Multiple Inheritance
  • 55. Example – Multiple Inheritance Land Vehicle Vehicle Water Vehicle Car Amphibious Vehicle Boot
  • 56.
  • 57.
  • 58. ..Problems with multiple Inheritance..
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.