Object-Oriented Programming (OOP) Lecture No. 4. Recap – Inheritance ► Derived class inherits all the characteristics of the base class ► Besides inherited.

Slides:



Advertisements
Similar presentations
General OO Concepts Objectives For Today: Discuss the benefits of OO Programming Inheritance and Aggregation Abstract Classes Encapsulation Introduce Visual.
Advertisements

This lecture is a bit of a departure in that we’ll cover how C++’s features are actually implemented. This implementation will look suspiciously similar.
Inheritance Math 130 B Smith: Consider using the example in SAMS Teach Yourself C++ in 24 hours B Smith: Consider using the example in SAMS Teach Yourself.
Copyright © 2012 Pearson Education, Inc. Chapter 4 Inheritance and Polymorphism.
Object-Oriented PHP (3) Intermediate OO Concepts & Practice (2)
CIS 234: Inheritance Dr. Ralph D. Westfall April, 2010.
ACM/JETT Workshop - August 4-5, :Inheritance and Interfaces.
Overview of Java (continue). Announcements You should have access to your repositories and HW0 If you have problems getting HW0, let me know If you’ve.
Object-Oriented Programming (OOP) Lecture No. 6
CS-2135 Object Oriented Programming
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,
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Fall 2007CS 2251 Inheritance and Class Hierarchies Chapter 3.
Fall 2007CS 2251 Inheritance and Class Hierarchies Chapter 3.
HST 952 Computing for Biomedical Scientists Lecture 2.
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.
CSSE501 Object-Oriented Development
2.5 OOP Principles Part 1 academy.zariba.com 1. Lecture Content 1.Fundamental Principles of OOP 2.Inheritance 3.Abstraction 4.Encapsulation 2.
1 INTRODUCTION TO OOP Objective: Know the difference between functional programming and OOP Know basic terminology in OOP Know the importance of OOP Know.
2.5 OOP Principles Part 2 academy.zariba.com 1. Lecture Content 1.Polymorphism 2.Cohesion 3.Coupling 2.
Using Jeroo To Teach Object-Oriented Concepts By Christian Digout.
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
Dr. Ahmad R. Hadaegh A.R. Hadaegh California State University San Marcos (CSUSM) Page 1 Virtual Functions Polymorphism Abstract base classes.
Introduction to Object-oriented programming and software development Lecture 1.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
Lecture 9 Polymorphism Richard Gesick.
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.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
1 Object-Oriented Programming: Polymorphism 10.1 Introduction 10.2 Relationships Among Objects in an Inheritance Hierarchy Invoking Superclass Methods.
© 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.
Copyright 2005, The Ohio State University 1 Inheritance What is Inheritance? Overriding vs. Overloading Access Control –Inheritance Types Virtual Functions.
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.
Ch. 2 Discussion Head First Java. Big Idea Differene between a class and an object What benefit object-oriented programming gives you. Read “Chair Wars”
Java Programming Dr. Randy Kaplan. Abstract Classes and Methods.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Introduction to Object-Oriented Programming Lesson 2.
Object-Oriented Programming (OOP) Lecture No. 4 Downloaded From:
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
© 2007 Lawrenceville Press Slide 1 Chapter 9 Inheritance  One class is an extension of another.  Allows a class to define a specialized type of an existing.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Object Modeling THETOPPERSWAY.COM. Object Modelling Technique(OMT)  Building a model of an application domain and then adding implementation.
1 / 71 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 4 Programming Fundamentals using Java 1.
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.
Interfaces, Abstract Classes, and Polymorphism. What Is an Interface? An interface is the set of public methods in a class Java provides the syntax for.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
Class Relationships Lecture Oo08 Polymorphism. References n Booch, et al, The Unified Modeling Language User Guide, Chapt 10 p.125 n Fowler & Scott, UML.
CSC241 Object-Oriented Programming (OOP) Lecture No. 2.
Object-Oriented Paradigm (OOP) Course Code: SE 101 Lecture No. 1.
CSC241 Object-Oriented Programming (OOP) Lecture No. 17.
Introduction to Object Oriented Programming Lecture-3.
CSC 205 Programming II Lecture 4 Abstract Class. The abstract keyword indicate that a class is not instantiable Defining a type which will be specialized.
Object-Oriented Programming (OOP) Lecture No. 1. Course Objective ► Objective of this course is to make students familiar with the concepts of object-oriented.
 The word static is used to declare either a ________ variable or method.  Why do we use statics?  What is Polymorphism? class In general, we use a.
Object-Oriented Programming (OOP) Lecture No. 4
Modern Programming Tools And Techniques-I
Intro to Computer Science II
Week 4 Object-Oriented Programming (1): Inheritance
Inheritance Chapter 5.
MSIS 670 Object-Oriented Software Engineering
Polymorphism Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan.
Object-Oriented Programming (OOP) Lecture No. 5
2 types of scale factor problems
Fundaments of Game Design
Object-Oriented Programming (OOP) Lecture No. 27
Computer Science II for Majors
Presentation transcript:

Object-Oriented Programming (OOP) Lecture No. 4

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