Your SlideShare is downloading. ×
OOP CLASS + INHERITANCE
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

OOP CLASS + INHERITANCE

367
views

Published on

NHERITANCE

NHERITANCE

Published in: Education, Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
367
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Object-Oriented ProgrammingObject-Oriented Programming (OOP)(OOP) Lecture No. 3Lecture No. 3
  • 2. AbstractionAbstraction ►Abstraction is a way to cope withAbstraction is a way to cope with complexity.complexity. ►Principle of abstraction:Principle of abstraction: ““Capture only those details about an objectCapture only those details about an object that are relevant to current perspective”that are relevant to current perspective”
  • 3. Example – AbstractionExample – Abstraction ►AttributesAttributes - Name- Name - Employee ID- Employee ID - Student Roll No- Student Roll No - Designation- Designation - Year of Study- Year of Study - Salary- Salary - CGPA- CGPA - Age- Age Ali is a PhD student and teaches BS students
  • 4. Example – AbstractionExample – Abstraction Ali is a PhD student and teaches BS students ►behaviourbehaviour - Study- Study - DevelopExam- DevelopExam - GiveExam- GiveExam - TakeExam- TakeExam - PlaySports- PlaySports - Eat- Eat - DeliverLecture- DeliverLecture - Walk- Walk
  • 5. Example – AbstractionExample – Abstraction ►AttributesAttributes - Name- Name - Employee ID- Employee ID - Student Roll No- Student Roll No - Designation- Designation - Year of Study- Year of Study - Salary- Salary - CGPA- CGPA - Age- Age Student’s Perspective
  • 6. Example – AbstractionExample – Abstraction Student’s Perspective ►behaviourbehaviour - Study- Study - DevelopExam- DevelopExam - GiveExam- GiveExam - TakeExam- TakeExam - PlaySports- PlaySports - Eat- Eat - DeliverLecture- DeliverLecture - Walk- Walk
  • 7. Example – AbstractionExample – Abstraction ►AttributesAttributes - Name- Name - Employee ID- Employee ID - Student Roll No- Student Roll No - Designation- Designation - Year of Study- Year of Study - Salary- Salary - CGPA- CGPA - Age- Age Teacher’s Perspective
  • 8. Example – AbstractionExample – Abstraction Teacher’s Perspective ►behaviourbehaviour - Study- Study - DevelopExam- DevelopExam - GiveExam- GiveExam - TakeExam- TakeExam - PlaySports- PlaySports - Eat- Eat - DeliverLecture- DeliverLecture - Walk- Walk
  • 9. Example – AbstractionExample – Abstraction ►Ordinary PerspectiveOrdinary Perspective A pet animal withA pet animal with  Four LegsFour Legs  A TailA Tail  Two EarsTwo Ears  Sharp TeethSharp Teeth ►Surgeon’s PerspectiveSurgeon’s Perspective A being withA being with  A SkeletonA Skeleton  HeartHeart  KidneyKidney  StomachStomach A cat can be viewed with different perspectives
  • 10. Example – AbstractionExample – Abstraction Driver’s View Engineer’s View
  • 11. Abstraction – AdvantagesAbstraction – Advantages ►Simplifies the model by hiding irrelevantSimplifies the model by hiding irrelevant detailsdetails ►Abstraction provides the freedom to deferAbstraction provides the freedom to defer implementation decisions by avoidingimplementation decisions by avoiding commitment to detailscommitment to details
  • 12. ClassesClasses ►In an OO model, some of the objects exhibitIn an OO model, some of the objects exhibit identical characteristics (informationidentical characteristics (information structure and behaviour)structure and behaviour) ►We say that they belong to the same classWe say that they belong to the same class
  • 13. Example – ClassExample – Class ►Ali studies mathematicsAli studies mathematics ►Anam studies physicsAnam studies physics ►Sohail studies chemistrySohail studies chemistry ►Each one is a StudentEach one is a Student ►We say these objects areWe say these objects are instancesinstances of theof the Student classStudent class
  • 14. Example – ClassExample – Class ►Ahsan teaches mathematicsAhsan teaches mathematics ►Aamir teaches computer scienceAamir teaches computer science ►Atif teaches physicsAtif teaches physics ►Each one is a teacherEach one is a teacher ►We say these objects areWe say these objects are instancesinstances of theof the Teacher classTeacher class
  • 15. Graphical Representation of ClassesGraphical Representation of Classes (Class Name) (attributes) (operations) (Class Name) Normal Form Suppressed Form
  • 16. Example – Graphical RepresentationExample – Graphical Representation of Classesof Classes Circle center radius draw computeArea Normal Form Suppressed Form Circle
  • 17. Example – Graphical RepresentationExample – Graphical Representation of Classesof Classes Person name age gender eat walk Normal Form Suppressed Form Person
  • 18. InheritanceInheritance ►A child inherits characteristics of its parentsA child inherits characteristics of its parents ►Besides inherited characteristics, a childBesides inherited characteristics, a child may have its own unique characteristicsmay have its own unique characteristics
  • 19. Inheritance in ClassesInheritance in Classes ►If a class B inherits from class A then itIf a class B inherits from class A then it contains all the characteristics (informationcontains all the characteristics (information structure and behaviour) of class Astructure and behaviour) of class A ►The parent class is calledThe parent class is called basebase class andclass and the child class is calledthe child class is called derivedderived classclass ►Besides inherited characteristics, derivedBesides inherited characteristics, derived class may have its own uniqueclass may have its own unique characteristicscharacteristics
  • 20. Example – InheritanceExample – Inheritance Person Teacher DoctorStudent
  • 21. Example – InheritanceExample – Inheritance Shape Circle TriangleLine
  • 22. Inheritance – “IS A” orInheritance – “IS A” or “IS A KIND OF” Relationship“IS A KIND OF” Relationship ►Each derived class is a special kind of itsEach derived class is a special kind of its base classbase class
  • 23. Example – “IS A” RelationshipExample – “IS A” Relationship Person name age gender eat walk Teacher designation salary teach takeExam Student program studyYear study heldExam Doctor designation salary checkUp prescribe
  • 24. Example – “IS A” RelationshipExample – “IS A” Relationship Shape color coord draw rotate setColor Circle radius draw computeArea Line length draw Triangle angle draw computeArea
  • 25. Inheritance – AdvantagesInheritance – Advantages ►ReuseReuse ►Less redundancyLess redundancy ►Increased maintainabilityIncreased maintainability
  • 26. Reuse with InheritanceReuse with Inheritance ►Main purpose of inheritance is reuseMain purpose of inheritance is reuse ►We can easily add new classes by inheritingWe can easily add new classes by inheriting from existing classesfrom existing classes  Select an existing class closer to the desiredSelect an existing class closer to the desired functionalityfunctionality  Create a new class and inherit it from theCreate a new class and inherit it from the selected classselected class  Add to and/or modify the inherited functionalityAdd to and/or modify the inherited functionality
  • 27. Example ReuseExample Reuse Shape color coord draw rotate setColor Circle radius draw computeArea Line length draw Triangle angle draw computeArea
  • 28. Example ReuseExample Reuse Person name age gender eat walk Teacher designation salary teach takeExam Student program studyYear study heldExam Doctor designation salary checkUp prescribe
  • 29. Example ReuseExample Reuse Person name age gender eat walk Teacher designation salary teach takeExam Student program studyYear study heldExam Doctor designation salary checkUp prescribe