2006 Pearson Education, Inc. All rights reserved. 1 12 Object-Oriented Programming: Inheritance.

Slides:



Advertisements
Similar presentations
2006 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Polymorphism.
Advertisements

Advanced Piloting Cruise Plot.
Chapter 6 Structures and Classes. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-2 Learning Objectives Structures Structure types Structures.
Chapter 14 Inheritance. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives Inheritance Basics Derived classes, with.
© 2008 Pearson Addison Wesley. All rights reserved Chapter Seven Costs.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Chapter 1 The Study of Body Function Image PowerPoint
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 1 Embedded Computing.
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 5 Author: Julia Richards and R. Scott Hawley.
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
UNITED NATIONS Shipment Details Report – January 2006.
1 What is Inheritance? A form of software reuse Create new class from existing class Absorb existing class data and behaviors Enhance with new or modified.
Outline 1 Introduction 2 Base Classes and Derived Classes 3 protected Members 4 Relationship between Base Classes and Derived Classes 5 Case Study: Three-Level.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Year 6 mental test 5 second questions
Year 6 mental test 10 second questions
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
ABC Technology Project
1 Undirected Breadth First Search F A BCG DE H 2 F A BCG DE H Queue: A get Undiscovered Fringe Finished Active 0 distance from A visit(A)
VOORBLAD.
1 Breadth First Search s s Undiscovered Discovered Finished Queue: s Top of queue 2 1 Shortest path from s.
Copyright © 2013, 2009, 2006 Pearson Education, Inc.
BIOLOGY AUGUST 2013 OPENING ASSIGNMENTS. AUGUST 7, 2013  Question goes here!
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
© 2012 National Heart Foundation of Australia. Slide 2.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
Addition 1’s to 20.
Model and Relationships 6 M 1 M M M M M M M M M M M M M M M M
25 seconds left…...
H to shape fully developed personality to shape fully developed personality for successful application in life for successful.
Januar MDMDFSSMDMDFSSS
Week 1.
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Intracellular Compartments and Transport
PSSA Preparation.
Immunobiology: The Immune System in Health & Disease Sixth Edition
Essential Cell Biology
Immunobiology: The Immune System in Health & Disease Sixth Edition
CpSc 3220 Designing a Database
 2005 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Inheritance.
C++ Inheritance Systems Programming.
 2006 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Inheritance.
Unit 5 School of Information Systems & Technology1 School of Information Systems and Technology (IST)
 2005 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Inheritance.
 2005 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Inheritance.
Chapter 12 Object-Oriented Programming: Inheritance Chapter 12 Object-Oriented Programming: Inheritance Part I.
 2005 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Inheritance.
 2009 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Inheritance.
Inheritance. Lecture contents Inheritance Class hierarchy Types of Inheritance Derived and Base classes derived class constructors protected access identifier.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Inheritance.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 9 - Object-Oriented Programming: Inheritance Outline 9.1 Introduction 9.2 Base Classes and Derived.
Part -1 © by Pearson Education, Inc. All Rights Reserved.
Object-Oriented Programming: Inheritance
Object-Oriented Programming: Inheritance
Chapter 9 Object-Oriented Programming: Inheritance
Object-Oriented Programming: Inheritance
Object-Oriented Programming: Inheritance
Recitation Course 0610 Speaker: Liu Yu-Jiun.
Object-Oriented Programming: Inheritance
Presentation transcript:

2006 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Inheritance

2006 Pearson Education, Inc. All rights reserved Introduction Inheritance – Software reusability – Create new class from existing class Absorb existing class s data and behaviors Enhance with new capabilities – Derived class inherits from base class Derived class – More specialized group of objects – Behaviors inherited from base class Can customize – Additional behaviors

2006 Pearson Education, Inc. All rights reserved Introduction (Cont.) Class hierarchy – Single inheritance Inherits from one base class – Multiple inheritance Inherits from multiple base classes – Base classes possibly unrelated More details in chapter 24

2006 Pearson Education, Inc. All rights reserved Introduction (Cont.) Three types of visibility – public Every object of derived class is also an object of base class – Base-class objects are not objects of derived classes – Example: All cars are vehicles, but not all vehicles are cars Can access non- private members of base class – To access private base-class members Derived class must use inherited non- private member functions – private Alternative to composition Chapter 21 – protected Rarely used

2006 Pearson Education, Inc. All rights reserved Introduction (Cont.) Abstraction – Focus on commonalities among objects in system is-a vs. has-a – is-a Inheritance Derived class object can be treated as base class object Example: Car is a vehicle – Vehicle properties/behaviors also apply to a car – has-a Composition Object contains one or more objects of other classes as members Example: Car has a steering wheel

2006 Pearson Education, Inc. All rights reserved Base Classes and Derived Classes (Cont.) Inheritance hierarchy – Inheritance relationships: tree-like hierarchy structure – Each class becomes Base class – Supplies data/behaviors to other classes OR Derived class – Inherits data/behaviors from other classes

2006 Pearson Education, Inc. All rights reserved. 7 Fig | Inheritance hierarchy for university CommunityMember s.

2006 Pearson Education, Inc. All rights reserved. 8 Fig | Inheritance hierarchy for Shapes.

2006 Pearson Education, Inc. All rights reserved Base Classes and Derived Classes (Cont.) public inheritance – Specify with : Class TwoDimensionalShape : public Shape Class TwoDimensionalShape inherits from class Shape – Base class private members Not accessible directly Still inherited – Manipulated through inherited public member functions – Base class public and protected members Inherited with original member access – friend functions Not inherited

2006 Pearson Education, Inc. All rights reserved protected Members protected access – Intermediate level of protection between public and private – protected members are accessible to Base class members Base class friend s Derived class members Derived class friend s Derived-class members – Refer to public and protected members of base class Simply use member names – Redefined base class members can be accessed by using base-class name and binary scope resolution operator ( :: )

2006 Pearson Education, Inc. All rights reserved CommissionEmployee - BasePlusCommissionEmployee Inheritance Hierarchy Using protected Data Use protected data – Enable class BasePlusCommissionEmployee to directly access base class data members – Base class s protected members are inherited by all derived classes of that base class

2006 Pearson Education, Inc. All rights reserved. 12 Outline Commission Employee.h (1 of 2)

2006 Pearson Education, Inc. All rights reserved. 13 Outline Commission Employee.h (2 of 2) Declare protected data

2006 Pearson Education, Inc. All rights reserved. 14 Outline Commission Employee.cpp (1 of 4)

2006 Pearson Education, Inc. All rights reserved. 15 Outline Commission Employee.cpp (4 of 4)

2006 Pearson Education, Inc. All rights reserved. 16 Outline BasePlus Commission Employee.h (1 of 1) BasePlusCommissionEmployee still inherits public ly from CommissionEmployee

2006 Pearson Education, Inc. All rights reserved. 17 Outline BasePlus Commission Employee.cpp (1 of 2) Call base-class constructor using base-class initializer syntax

2006 Pearson Education, Inc. All rights reserved. 18 Outline BasePlus Commission Employee.cpp (2 of 2) Directly access base classs protected data

2006 Pearson Education, Inc. All rights reserved. 19 Outline Fig12_16.cpp (1 of 3)

2006 Pearson Education, Inc. All rights reserved. 20 Outline Fig12_16.cpp (2 of 3)

2006 Pearson Education, Inc. All rights reserved. 21 Outline Fig12_16.cpp (3 of 3)

2006 Pearson Education, Inc. All rights reserved CommissionEmployee - BasePlusCommissionEmployee Inheritance Hierarchy Using private Data Reexamine hierarchy – Use the best software engineering practice Declare data members as private Provide public get and set functions Use get method to obtain values of data members

2006 Pearson Education, Inc. All rights reserved. 23 Outline Commission Employee.h (1 of 2)

2006 Pearson Education, Inc. All rights reserved. 24 Outline Commission Employee.h (2 of 2) Declare private data

2006 Pearson Education, Inc. All rights reserved. 25 Outline Commission Employee.cpp (1 of 4) Use member initializers to set the values of members firstName, lastname and socialSecurityNumber

2006 Pearson Education, Inc. All rights reserved. 26 Outline Commission Employee.cpp (2 of 4)

2006 Pearson Education, Inc. All rights reserved. 27 Outline Commission Employee.cpp (3 of 4) Use get functions to obtain the values of data members

2006 Pearson Education, Inc. All rights reserved. 28 Outline Commission Employee.cpp (4 of 4) Use get functions to obtain the values of data members

2006 Pearson Education, Inc. All rights reserved public, protected and private Inheritance public inheritance – Base class public members derived class public members – Base class protected members derived class protected members – Base class private members are not accessible private inheritance (not is-a relationship) – Base class public and protected members derived class private members

2006 Pearson Education, Inc. All rights reserved Software Engineering with Inheritance Customizing existing software – Inheriting from existing classes Can include additional members Can redefine base-class members No direct access to base class s source code – Only links to object code – Independent software vendors (ISVs) Develop proprietary code for sale/license – Available in object-code format Users derive new classes – Without accessing ISV proprietary source code