CSC241 Object-Oriented Programming (OOP) Lecture No. 2.

Slides:



Advertisements
Similar presentations
1 Inheritance Classes and Subclasses Or Extending a Class.
Advertisements

General OO Concepts Objectives For Today: Discuss the benefits of OO Programming Inheritance and Aggregation Abstract Classes Encapsulation Introduce Visual.
OBJECT ORIENTED PROGRAMMING M Taimoor Khan
Inheritance & Classification Hierarchies Lecture-8.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
Object-Oriented Programming (OOP) Lecture No. 6
CS-2135 Object Oriented Programming
L3-1-S1 OO Concepts © M.E. Fayad SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
Fall 2007CS 2251 Inheritance and Class Hierarchies Chapter 3.
Stéphane Ducasse6.1 Essential Concepts Why OO? What is OO? What are the benefits? What are the KEY concepts? Basis for all the lectures.
1 Inheritance Inheritance is a natural way to model the world in object-oriented programming. It is used when you have two types of objects where one is.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
CSCI-383 Object-Oriented Programming & Design Lecture 15.
(c) University of Washington03-1 CSC 143 Java Inheritance Reading: Ch. 10.
2.5 OOP Principles Part 1 academy.zariba.com 1. Lecture Content 1.Fundamental Principles of OOP 2.Inheritance 3.Abstraction 4.Encapsulation 2.
Using Jeroo To Teach Object-Oriented Concepts By Christian Digout.
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
Introduction to Object-oriented programming and software development Lecture 1.
Object Oriented Programming Lecturer: Andreas P. Adi
O BJECT O RIENTATION F UNDAMENTALS Prepared by: Gunjan Chhabra.
An Object-Oriented Approach to Programming Logic and Design
Object-Oriented Programming (OOP) Lecture No. 3. Abstraction ► Abstraction is a way to cope with complexity. ► Principle of abstraction: “Capture only.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
3rd Country Training, K.Subieta: System Engineering and Databases. Lecture 3, Slide 1 February 20, 2004 Lecture 3: Introduction to Software Analysis and.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
© S Ramakrishnan, Monash University oops1.ppt 1 Object-Oriented Programming Systems SFT3021 Semester Lecturer: Sita Ramakrishnan
Object-Oriented Programming (OOP) CSC-2071 (3+1=4 Credits) Lecture No. 1 MBY.
Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.
Object Oriented Programming Principles Lecturer: Kalamullah Ramli Electrical Engineering Dept. University of Indonesia Session-3.
CHAPTER 13 (ONLINE): OBJECT-ORIENTED DATA MODELING © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database Management 11 th Edition.
Object-Oriented Programming (OOP) Lecture No. 4. Recap – Inheritance ► Derived class inherits all the characteristics of the base class ► Besides inherited.
Polymorphism, Abstraction and Virtual Functions. In this slide, we introduce virtual functions and two complex and powerful uses for derived classes that.
Design.ppt1 Top-down designs: 1. Define the Problem IPO 2. Identify tasks, Modularize 3. Use structure chart 4. Pseudocode for Mainline 5. Construct pseudocode.
CSC241 Object-Oriented Programming (OOP) Lecture No. 1.
CSC241 Object-Oriented Programming (OOP) Lecture No. 3.
Copyright (c) 1998, 1999 D.L. Bailey * Winter 1999 Part 6 Reusing Classes: Inheritance and Composition.
Peyman Dodangeh Sharif University of Technology Fall 2014.
Object-Oriented Data Modeling
Object-Oriented Modeling: Static Models. Object-Oriented Modeling Model the system as interacting objects Model the system as interacting objects Match.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
CSCI-383 Object-Oriented Programming & Design Lecture 10.
Object Oriented Programming
OOP (Object Oriented Programming) Lecture 1. Why a new paradigm is needed? Complexity Five attributes of complex systems –Frequently, complexity takes.
C++ Inheritance Data Structures & OO Development I 1 Computer Science Dept Va Tech June 2007 © McQuain Generalization versus Abstraction Abstraction:simplify.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Object-Oriented Programming (OOP) Lecture No. 4 Downloaded From:
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
Object Modeling THETOPPERSWAY.COM. Object Modelling Technique(OMT)  Building a model of an application domain and then adding implementation.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
Object-Oriented Paradigm (OOP) Course Code: SE 101 Lecture No. 1.
Introduction to Object Oriented Programming Lecture-3.
Object-Oriented Programming (OOP) Lecture No. 1. Course Objective ► Objective of this course is to make students familiar with the concepts of object-oriented.
CSCI 383 Object-Oriented Programming & Design Lecture 15 Martin van Bommel.
Object-Oriented Programming (OOP) Lecture No. 4
Modern Programming Tools And Techniques-I
Object Oriented Programming
Object-Oriented Programming Concepts
Sachin Malhotra Saurabh Choudhary
Inheritance and Polymorphism
Programming in Java Sachin Malhotra, Chairperson, PGDM-IT, IMS Ghaziabad Saurabh Chaudhary, Dean, Academics, IMS Ghaziabad.
Week 4 Object-Oriented Programming (1): Inheritance
An Introduction to Inheritance
Road Map Inheritance Class hierarchy Overriding methods Constructors
Object Oriented Analysis and Design
Inheritance Chapter 5.
Object-Oriented Programming
Object Oriented Design & Analysis
Presentation transcript:

CSC241 Object-Oriented Programming (OOP) Lecture No. 2

Abstraction  Abstraction is a way to cope with complexity.  Principle of abstraction: “Capture only those details about an object that are relevant to current perspective”

Example – Abstraction  Attributes - Name- Employee ID - Student Roll No- Designation - Year of Study- Salary - CGPA- Age Ali is a PhD student and teaches BS students

Example – Abstraction  behaviour - Study- DevelopExam - GiveExam- TakeExam - PlaySports- Eat - DeliverLecture- Walk Ali is a PhD student and teaches BS students

Example – Abstraction  Attributes - Name- Employee ID - Student Roll No- Designation - Year of Study- Salary - CGPA- Age Student’s Perspective

Example – Abstraction  behaviour - Study- DevelopExam - GiveExam- TakeExam - PlaySports- Eat - DeliverLecture- Walk Student’s Perspective

Example – Abstraction  Attributes - Name- Employee ID - Student Roll No- Designation - Year of Study- Salary - CGPA- Age Teacher’s Perspective

Example – Abstraction  behaviour - Study- DevelopExam - GiveExam- TakeExam - PlaySports- Eat - DeliverLecture- Walk Teacher’s Perspective

Example – Abstraction  Ordinary Perspective A pet animal with  Four Legs  A Tail  Two Ears  Sharp Teeth  Surgeon’s Perspective A being with  A Skeleton  Heart  Kidney  Stomach A cat can be viewed with different perspectives

Example – Abstraction Driver’s View Engineer’s View

Abstraction – Advantages  Simplifies the model by hiding irrelevant details  Abstraction provides the freedom to defer implementation decisions by avoiding commitment to details

Classes  In an OO model, some of the objects exhibit identical characteristics (information structure and behaviour)  We say that they belong to the same class

Example – Class  Ali studies mathematics  Anam studies physics  Sohail studies chemistry  Each one is a Student  We say these objects are instances of the Student class

Example – Class  Ahsan teaches mathematics  Aamir teaches computer science  Atif teaches physics  Each one is a teacher  We say these objects are instances of the Teacher class

Graphical Representation of Classes (Class Name) (attributes) (operations) (Class Name) Normal Form Suppressed Form

Example – Graphical Representation of Classes Circle center radius draw computeArea Normal Form Suppressed Form Circle

Example – Graphical Representation of Classes Person name age gender eat walk Normal Form Suppressed Form Person

Inheritance  A child inherits characteristics of its parents  Besides inherited characteristics, a child may have its own unique characteristics

Inheritance in Classes  If a class B inherits from class A then it contains all the characteristics (information structure and behaviour) of class A  The parent class is called base class and the child class is called derived class  Besides inherited characteristics, derived class may have its own unique characteristics

Example – Inheritance Person Teacher Doctor Student

Example – Inheritance Shape Circle Triangle Line

Inheritance – “IS A” or “IS A KIND OF” Relationship  Each derived class is a special kind of its base class

Example – “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” Relationship Shape color coord draw rotate setColor Circle radius draw computeArea Line length draw Triangle angle draw computeArea

Inheritance – Advantages  Reuse  Less redundancy  Increased maintainability

Reuse with Inheritance  Main purpose of inheritance is reuse  We can easily add new classes by inheriting from existing classes  Select an existing class closer to the desired functionality  Create a new class and inherit it from the selected class  Add to and/or modify the inherited functionality

Example Reuse Shape color coord draw rotate setColor Circle radius draw computeArea Line length draw Triangle angle draw computeArea

Example Reuse Person name age gender eat walk Teacher designation salary teach takeExam Student program studyYear study heldExam Doctor designation salary checkUp prescribe

Example Reuse Person name age gender eat walk Teacher designation salary teach takeExam Student program studyYear study heldExam Doctor designation salary checkUp prescribe

Recap – Inheritance  Derived class inherits all the characteristics of the base class  Besides inherited characteristics, derived class may have its own unique characteristics  Major benefit of inheritance is reuse

Concepts Related with Inheritance  Generalization  Subtyping (extension)  Specialization (restriction)

Generalization  In OO models, some classes may have common characteristics  We extract these features into a new class and inherit original classes from this new class  This concept is known as Generalization

Example – Generalization Circle color vertices radius move setColor computeArea Line color vertices length move setColor getLength Triangle color vertices angle move setColor computeArea

Example – Generalization Shape color vertices move setColor Circle radius computeArea Line length getLength Triangle angle computeArea

Example – Generalization Teacher name age gender designation salary teach takeExam eat walk Student name age gender program studyYear study heldExam eat walk Doctor name age gender designation salary checkUp prescribe eat walk

Example – Generalization Person name age gender eat walk Teacher designation salary teach takeExam Student program studyYear study heldExam Doctor designation salary checkUp prescribe

Sub-typing & Specialization  We want to add a new class to an existing model  Find an existing class that already implements some of the desired state and behaviour  Inherit the new class from this class and add unique behaviour to the new class

Sub-typing (Extension)  Sub-typing means that derived class is behaviourally compatible with the base class  Behaviourally compatible means that base class can be replaced by the derived class

Example – Sub-typing (Extension) Person name age gender eats walks Student program studyYear study takeExam

Example – Sub- typing (Extension) Shape color vertices setColor move Circle radius computeCF computeArea

Specialization (Restriction)  Specialization means that derived class is behaviourally incompatible with the base class  Behaviourally incompatible means that base class can’t always be replaced by the derived class

Example – Specialization (Restriction) Person age : [0..100] … Adult age : [ ] … setAge( a ) … setAge( a ) … age = a If age < 18 then error else age = a

Example – Specialization (Restriction) IntegerSet … NaturalSet … add( elem ) … add( elem ) … add element to the set If elem < 1 then error else add element to the set

Overriding  A class may need to override the default behaviour provided by its base class  Reasons for overriding  Provide behaviour specific to a derived class  Extend the default behaviour  Restrict the default behaviour  Improve performance

Example – Specific Behaviour Shape color vertices draw move setColor Circle radius draw computeArea Line length draw Triangle angle draw computeArea

Example – Extension Window width height open close draw DialogBox controls enable draw 1- Invoke Window’s draw 2- draw the dialog box

Example – Restriction IntegerSet … NaturalSet … add( elem ) … add( elem ) … Add element to the set If elem < 1 then give error else Add element to the set

Example – Improve Performance  Class Circle overrides rotate operation of class Shape with a Null operation. Shape color coord draw rotate setColor Circle radius draw rotate

Abstract Classes  An abstract class implements an abstract concept  Main purpose is to be inherited by other classes  Can’t be instantiated  Promotes reuse

Example – Abstract Classes Teacher DoctorStudent  Here, Person is an abstract class Person name age gender eat walk

Example – Abstract Classes Bus Truck Car  Here, Vehicle is an abstract class Vehicle color model accelerate applyBrakes

Concrete Classes  A concrete class implements a concrete concept  Main purpose is to be instantiated  Provides implementation details specific to the domain context

Example – Concrete Classes  Here, Student, Teacher and Doctor are concrete classes Teacher Doctor Student program studyYear study heldExam Person

Example – Concrete Classes Here, Car, Bus and Truck are concrete classes Bus Car Vehicle Truck capacity load unload