Oop +  lecture03
Upcoming SlideShare
Loading in...5
×
 

Oop + lecture03

on

  • 255 views

 

Statistics

Views

Total Views
255
Views on SlideShare
255
Embed Views
0

Actions

Likes
0
Downloads
5
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Oop +  lecture03 Oop + lecture03 Presentation Transcript

  • Object-Oriented ProgrammingObject-Oriented Programming (OOP)(OOP) Lecture No. 3Lecture No. 3
  • 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”
  • 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
  • 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
  • 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
  • Example – AbstractionExample – Abstraction Student’s Perspective ►behaviourbehaviour - Study- Study - DevelopExam- DevelopExam - GiveExam- GiveExam - TakeExam- TakeExam - PlaySports- PlaySports - Eat- Eat - DeliverLecture- DeliverLecture - Walk- Walk
  • 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
  • Example – AbstractionExample – Abstraction Teacher’s Perspective ►behaviourbehaviour - Study- Study - DevelopExam- DevelopExam - GiveExam- GiveExam - TakeExam- TakeExam - PlaySports- PlaySports - Eat- Eat - DeliverLecture- DeliverLecture - Walk- Walk
  • 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
  • Example – AbstractionExample – Abstraction Driver’s View Engineer’s View
  • 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
  • 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
  • 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
  • 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
  • Graphical Representation of ClassesGraphical Representation of Classes (Class Name) (attributes) (operations) (Class Name) Normal Form Suppressed Form
  • Example – Graphical RepresentationExample – Graphical Representation of Classesof Classes Circle center radius draw computeArea Normal Form Suppressed Form Circle
  • Example – Graphical RepresentationExample – Graphical Representation of Classesof Classes Person name age gender eat walk Normal Form Suppressed Form Person
  • 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
  • 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
  • Example – InheritanceExample – Inheritance Person Teacher DoctorStudent
  • Example – InheritanceExample – Inheritance Shape Circle TriangleLine
  • 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
  • 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
  • Example – “IS A” RelationshipExample – “IS A” Relationship Shape color coord draw rotate setColor Circle radius draw computeArea Line length draw Triangle angle draw computeArea
  • Inheritance – AdvantagesInheritance – Advantages ►ReuseReuse ►Less redundancyLess redundancy ►Increased maintainabilityIncreased maintainability
  • 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
  • Example ReuseExample Reuse Shape color coord draw rotate setColor Circle radius draw computeArea Line length draw Triangle angle draw computeArea
  • Example ReuseExample Reuse Person name age gender eat walk Teacher designation salary teach takeExam Student program studyYear study heldExam Doctor designation salary checkUp prescribe
  • Example ReuseExample Reuse Person name age gender eat walk Teacher designation salary teach takeExam Student program studyYear study heldExam Doctor designation salary checkUp prescribe