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