Inheritance: Introduction

Slides:



Advertisements
Similar presentations
LOGO Lecturer: Abdullahi Salad Abdi May 1, Object Oriented Programming in C++
Advertisements

L3-1-S1 OO Concepts © M.E. Fayad SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.
CSCI-383 Object-Oriented Programming & Design Lecture 15.
Specialization and generalization
LECTURE 07 Programming using C# Inheritance
2/9/98 Thomas O’Reilly 1 A Quick UML Introduction.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Ramez Elmasri and Shamkant Navathe Enhanced-ER (EER) Model Concepts.
Identifying Object Relationships, Attributes, and Methods
CS1201: Programming Language 2 Classes and objects Inheritance By: Nouf Aljaffan Edited by : Nouf Almunyif.
CSCI 171 Presentation 15 Introduction to Object–Oriented Programming (OOP) in C++
1 SWE Introduction to Software Engineering Lecture 14 – System Modeling.
Chapter 4_part2: The Enhanced Entity-Relationship (EER) Model.
Chapter 5 – System Modeling Lecture 1 1Chapter 5 System modeling.
Slide 1 Unified Modeling Language, Version 2.0 Object-Oriented SAD.
Identifying Object Relationships, Attributes, and Methods.
Engineering, 7th edition. Chapter 8 Slide 1 System models.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Advanced Programming in Java
Object Oriented Programming: Inheritance
Enhanced Entity-Relationship (EER) Model
The Enhanced Entity- Relationship (EER) Model
© Shamkant B. Navathe CC.
Conceptual Design & ERD Modelling
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING
The Enhanced Entity- Relationship (EER) Model
Enhanced Entity-Relationship (EER) Modeling
Session 2 Welcome: The sixth learning sequence
Enhanced Entity-Relationship (EER) Modeling
Inheritance CMSC 202, Version 4/02.
Objects as a programming concept
EKT472: Object Oriented Programming
Python First Edition STARTING OUT WITH Chapter 10 Inheritance
Week 4 Object-Oriented Programming (1): Inheritance
OBJECT RELATIONSHIPS, ATTRIBUTES, AND METHODS
Road Map Inheritance Class hierarchy Overriding methods Constructors
ATS Application Programming: Java Programming
Inheritance B.Ramamurthy 11/7/2018 B.Ramamurthy.
Chapter 10 Thinking in Objects
CSC 205 Java Programming II
Inheritance Basics Programming with Inheritance
Domain Class Diagram Chapter 4 Part 2 pp
Chapter 10 Thinking in Objects
Engineering Quality Software
Software Engineering Lecture #11.
© Shamkant B. Navathe CC.
Object Oriented Analysis and Design Using the UML
MSIS 670 Object-Oriented Software Engineering
The Object-Oriented Thought Process Chapter 07
Advanced Programming Behnam Hatami Fall 2017.
Software Engineering System Modeling Extra examples Dr.Doaa Sami
Two big words Inheritance Polymorphism
© Shamkant B. Navathe CC.
CS1201: Programming Language 2
Computer Programming with JAVA
CS4222 Principles of Database System
topics object oriented design objects and classes properties
Analysis and Design with UML: Classes and Relationships
Sampath Jayarathna Cal Poly Pomona
Workshop for Programming And Systems Management Teachers
ENHANCED ENTITY-RELATIONSHIP (EER) MODEL
Sampath Jayarathna Cal Poly Pomona
Object Oriented Analysis and Design
© Shamkant B. Navathe CC.
Enhanced Entity-Relationship (EER) Modeling
Object-Oriented Programming
Enhanced Entity-Relationship (EER) Modeling
Chapter 4 System Modeling.
Presentation transcript:

Inheritance: Introduction Lecture 25 Fri, Mar 19, 2004 1/17/2019 Inheritance

Topics Inheritance The IS-A relation The HAS-A relation 1/17/2019

Object-Oriented Programming The basic principle of object-oriented programming is to create objects and relationships between them that reflect reality. This should make the programming more intuitive. But it does take effort. 1/17/2019 Inheritance

Example: Relationships What are the relationships among the following types of object? human mammal dog bird animal tail 1/17/2019 Inheritance

Hierarchy of Objects Animal Mammal Bird Human Dog Tail 1/17/2019 Inheritance

Inheritance in C++ In C++ a new class may be derived from an existing class. The new class is called the derived class or the subclass. The original class is called the base class or the superclass. 1/17/2019 Inheritance

Inheritance in C++ The subclass inherits all the data members and member functions of the base class. The subclass also has its own data members and member functions. In addition, the subclass may redefine inherited functions. 1/17/2019 Inheritance

Example We could derive the Mammal class from the Animal class. We could derive the Human class from the Mammal class. Should we derive the Tail class from the Dog class? 1/17/2019 Inheritance

Design Decisions It is not always easy to decide when to derive one class from another. The decision should reflect the way we think about the classes. Two helpful relations IS-A HAS-A 1/17/2019 Inheritance

Hierarchy of Objects Animal Human Mammal Bird Dog Tail IS-A HAS-A 1/17/2019 Inheritance

General Guidelines Generally speaking, the hierarchy should go from the most general class at the top down to the most specific class at the bottom. Class A Class B Class C 1/17/2019 Inheritance

General Guidelines Generally speaking, the hierarchy should go from the most general class at the top down to the most specific class at the bottom. Class A Increasingly General Class B Class C 1/17/2019 Inheritance

General Guidelines Generally speaking, the hierarchy should go from the most general class at the top down to the most specific class at the bottom. Class A Increasingly General Increasingly Specific Class B Class C 1/17/2019 Inheritance

General Guidelines Generally speaking, the classes lower in the hierarchy should have all the attributes of the classes higher in the hierarchy, as well as additional attributes of their own. Class A Class B Class C 1/17/2019 Inheritance

General Guidelines Generally speaking, the classes lower in the hierarchy should have all the attributes of the classes higher in the hierarchy, as well as additional attributes of their own. Class A More Attributes Class B Class C 1/17/2019 Inheritance

General Guidelines Generally speaking, the classes lower in the hierarchy should have all the attributes of the classes higher in the hierarchy, as well as additional attributes of their own. Class A More Attributes More Methods Class B Class C 1/17/2019 Inheritance

The HAS-A Relation If an object of class A HAS a component that is an object of class B, then the HAS-A relation holds from class A to class B. If every class A object HAS-A class B component, then an object of class B should be a data member of class A. 1/17/2019 Inheritance

Example: HAS-A Relation A Car has an Engine. A Car has Wheels. The HAS-A relation holds from class Car to classes Engine and Wheels. class Engine; class Wheels; class Car { // Data members Engine e; Wheels w; }; 1/17/2019 Inheritance

The IS-A Relation If an object of class A IS an object of a more general class B, then the IS-A relation holds from class A to class B. If every class A object IS-A class B object, then class A should be derived as a subclass of class B. 1/17/2019 Inheritance

Example: IS-A Relation A Car is a Vehicle. The IS-A relation holds from class Car to class Vehicle. class Vehicle; class Car : public Vehicle { : }; 1/17/2019 Inheritance

Example: IS-A Relation Vehicle MotorVehicle {Engine} Bicycle {Wheels} Car {Wheels} MotorBoat {Rudder} 1/17/2019 Inheritance

Transitivity The IS-A relation is transitive. A Car IS-A MotorVehicle and a MotorVehicle IS-A Vehicle. Therefore, a Car IS-A Vehicle. Class inheritance is transitive. If class B is a subclass of class A and class C is a subclass of class B, then class C is a subclass of class A. Class C inherits data members and member functions from classes A and B. 1/17/2019 Inheritance